github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/errors/IdempotenceError.go (about) 1 package errors 2 3 import ( 4 "strconv" 5 6 "github.com/Ingenico-ePayments/connect-sdk-go/domain/errors" 7 ) 8 9 // IdempotenceError represents an error response from the Ingenico ePayments platform when an idempotent request failed because the first request has not finished yet. 10 type IdempotenceError struct { 11 idempotenceKey string 12 idempotenceRequestTimestamp *int64 13 14 errorMessage string 15 statusCode int 16 responseBody string 17 errorID string 18 errors []errors.APIError 19 } 20 21 // Message returns the error message 22 func (ie *IdempotenceError) Message() string { 23 return ie.errorMessage 24 } 25 26 // StatusCode returns the status code 27 func (ie *IdempotenceError) StatusCode() int { 28 return ie.statusCode 29 } 30 31 // ResponseBody returns the response body 32 func (ie *IdempotenceError) ResponseBody() string { 33 return ie.responseBody 34 } 35 36 // ErrorID returns the error id 37 func (ie *IdempotenceError) ErrorID() string { 38 return ie.errorID 39 } 40 41 // Errors returns a slice of underlying errors 42 func (ie *IdempotenceError) Errors() []errors.APIError { 43 // Return a clone instead of the original slice - immutability insurance 44 return append([]errors.APIError{}, ie.errors...) 45 } 46 47 // IdempotenceKey returns the idempotence key used 48 func (ie *IdempotenceError) IdempotenceKey() string { 49 return ie.idempotenceKey 50 } 51 52 // IdempotenceRequestTimestamp returns the timestamp of the request 53 func (ie *IdempotenceError) IdempotenceRequestTimestamp() *int64 { 54 var timestamp *int64 55 56 if ie.idempotenceRequestTimestamp == nil { 57 timestamp = nil 58 } else { 59 timestamp = new(int64) 60 61 *timestamp = *ie.idempotenceRequestTimestamp 62 } 63 64 return timestamp 65 } 66 67 // String implements the Stringer interface 68 // Format: 'errorMessage; statusCode=; responseBody=' 69 func (ie *IdempotenceError) String() string { 70 list := ie.errorMessage 71 72 if ie.statusCode > 0 { 73 list = list + "; statusCode=" + strconv.Itoa(ie.statusCode) 74 } 75 if len(ie.responseBody) != 0 { 76 list = list + "; responseBody='" + ie.responseBody + "'" 77 } 78 79 return list 80 } 81 82 // Error implements the Error interface 83 func (ie *IdempotenceError) Error() string { 84 return ie.String() 85 } 86 87 // NewIdempotenceError creates an IdempotenceError with the given idempotenceKey, idempotenceRequestTimestamp, statusCode, responseBody, errorID and errors 88 func NewIdempotenceError(idempotenceKey string, idempotenceRequestTimestamp *int64, statusCode int, responseBody, errorID string, errors []errors.APIError) (*IdempotenceError, error) { 89 return &IdempotenceError{idempotenceKey, idempotenceRequestTimestamp, "the Ingenico ePayments platform returned an incorrect request error response", statusCode, responseBody, errorID, errors}, nil 90 } 91 92 // NewIdempotenceErrorVerbose creates an IdempotenceError with the given idempotenceKey, idempotenceRequestTimestamp, message, statusCode, responseBody, errorID and errors 93 func NewIdempotenceErrorVerbose(idempotenceKey string, idempotenceRequestTimestamp *int64, message string, statusCode int, responseBody, errorID string, errors []errors.APIError) (*IdempotenceError, error) { 94 return &IdempotenceError{idempotenceKey, idempotenceRequestTimestamp, message, statusCode, responseBody, errorID, errors}, nil 95 }