github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/errors/GlobalCollectError.go (about)

     1  package errors
     2  
     3  import (
     4  	"strconv"
     5  
     6  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/errors"
     7  )
     8  
     9  // GlobalCollectError represents an error response from the Ingenico ePayments platform when something went wrong at the Ingenico ePayments platform or further downstream.
    10  type GlobalCollectError struct {
    11  	errorMessage string
    12  	statusCode   int
    13  	responseBody string
    14  	errorID      string
    15  	errors       []errors.APIError
    16  }
    17  
    18  // Message returns the error message
    19  func (gce *GlobalCollectError) Message() string {
    20  	return gce.errorMessage
    21  }
    22  
    23  // StatusCode returns the status code
    24  func (gce *GlobalCollectError) StatusCode() int {
    25  	return gce.statusCode
    26  }
    27  
    28  // ResponseBody returns the response body
    29  func (gce *GlobalCollectError) ResponseBody() string {
    30  	return gce.responseBody
    31  }
    32  
    33  // ErrorID returns the error id
    34  func (gce *GlobalCollectError) ErrorID() string {
    35  	return gce.errorID
    36  }
    37  
    38  // Errors returns a slice of underlying errors
    39  func (gce *GlobalCollectError) Errors() []errors.APIError {
    40  	// Return a clone instead of the original slice - immutability insurance
    41  	return append([]errors.APIError{}, gce.errors...)
    42  }
    43  
    44  // String implements the Stringer ineterface
    45  // Format: 'errorMessage; statusCode=; responseBody='
    46  func (gce *GlobalCollectError) String() string {
    47  	list := gce.errorMessage
    48  
    49  	if gce.statusCode > 0 {
    50  		list = list + "; statusCode=" + strconv.Itoa(gce.statusCode)
    51  	}
    52  	if len(gce.responseBody) != 0 {
    53  		list = list + "; responseBody='" + gce.responseBody + "'"
    54  	}
    55  
    56  	return list
    57  }
    58  
    59  // Error implements the Error interface
    60  func (gce *GlobalCollectError) Error() string {
    61  	return gce.String()
    62  }
    63  
    64  // NewGlobalCollectError creates a GlobalCollectError with the given statusCode, responseBody, errorID and errors
    65  func NewGlobalCollectError(statusCode int, responseBody, errorID string, errors []errors.APIError) (*GlobalCollectError, error) {
    66  	return &GlobalCollectError{"the Ingenico ePayments platform returned an error response", statusCode, responseBody, errorID, errors}, nil
    67  }
    68  
    69  // NewGlobalCollectErrorVerbose creates a GlobalCollectError with the given message, statusCode, responseBody, errorID and errors
    70  func NewGlobalCollectErrorVerbose(message string, statusCode int, responseBody, errorID string, errors []errors.APIError) (*GlobalCollectError, error) {
    71  	return &GlobalCollectError{message, statusCode, responseBody, errorID, errors}, nil
    72  }