-
Notifications
You must be signed in to change notification settings - Fork 11
/
api_error.go
46 lines (37 loc) · 1.1 KB
/
api_error.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
package abstractions
import "fmt"
type ApiErrorable interface {
SetResponseHeaders(ResponseHeaders *ResponseHeaders)
SetStatusCode(ResponseStatusCode int)
GetResponseHeaders() *ResponseHeaders
GetStatusCode() int
}
// ApiError is the parent type for errors thrown by the client when receiving failed responses to its requests
type ApiError struct {
Message string
ResponseStatusCode int
ResponseHeaders *ResponseHeaders
}
func (e *ApiError) Error() string {
if len(e.Message) > 0 {
return fmt.Sprint(e.Message)
} else {
return "error status code received from the API"
}
}
// NewApiError creates a new ApiError instance
func NewApiError() *ApiError {
return &ApiError{ResponseHeaders: NewResponseHeaders()}
}
func (e *ApiError) SetResponseHeaders(ResponseHeaders *ResponseHeaders) {
e.ResponseHeaders = ResponseHeaders
}
func (e *ApiError) SetStatusCode(ResponseStatusCode int) {
e.ResponseStatusCode = ResponseStatusCode
}
func (e *ApiError) GetResponseHeaders() *ResponseHeaders {
return e.ResponseHeaders
}
func (e *ApiError) GetStatusCode() int {
return e.ResponseStatusCode
}