This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
ResponseError.go
62 lines (49 loc) · 1.81 KB
/
ResponseError.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package errors
import (
"strconv"
"github.com/Ingenico-ePayments/connect-sdk-go/communicator/communication"
)
// ResponseError is returned when a response was received from the Ingenico ePayments platform which indicates an error.
type ResponseError struct {
statusCode int
body string
headers []communication.Header
}
// StatusCode gets the HTTP status code that was returned by the Ingenico ePayments platform.
func (e *ResponseError) StatusCode() int {
return e.statusCode
}
// Body gets the raw response body that was returned by the Ingenico ePayments platform.
func (e *ResponseError) Body() string {
return e.body
}
// Headers gets the headers that were returned by the Ingenico ePayments platform.
func (e *ResponseError) Headers() []communication.Header {
return e.headers
}
// GetHeader returns the header with the given name, or nil if there was no such header.
func (e *ResponseError) GetHeader(headerName string) *communication.Header {
return communication.Headers(e.headers).GetHeader(headerName)
}
// String implements the Stringer interface
// Format: 'errorMessage; statusCode=; responseBody='
func (e *ResponseError) String() string {
retString := "the Ingenico ePayments platform returned an error response"
statusCode := e.statusCode
if statusCode > 0 {
retString += "; statusCode=" + strconv.Itoa(e.statusCode)
}
responseBody := e.body
if len(responseBody) > 0 {
retString += "; responseBody='" + e.body + "'"
}
return retString
}
// Error implements the Error interface
func (e *ResponseError) Error() string {
return e.String()
}
// NewResponseError creates a new ResponseError with the specified response
func NewResponseError(statusCode int, body string, headers []communication.Header) *ResponseError {
return &ResponseError{statusCode: statusCode, body: body, headers: headers}
}