forked from Midtrans/midtrans-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
45 lines (37 loc) · 1.1 KB
/
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
package midtrans
import "fmt"
type Error struct {
Message string
StatusCode int
RawError error
RawApiResponse *ApiResponse
}
// Error returns error message.
// To comply midtrans.Error with Go error interface.
func (e *Error) Error() string {
if e.RawError != nil {
return fmt.Sprintf("%s: %s", e.Message, e.RawError.Error())
}
return e.Message
}
// Unwrap method that returns its contained error
// if there is RawError supplied during error creation, return RawError. Else, will return nil
func (e *Error) Unwrap() error {
return e.RawError
}
// GetMessage this get general message error when call api
func (e *Error) GetMessage() string {
return e.Message
}
// GetStatusCode this get api response status code coming from midtrans backend
func (e *Error) GetStatusCode() int {
return e.StatusCode
}
// GetRawApiResponse this get api raw response from midtrans backend
func (e *Error) GetRawApiResponse() *ApiResponse {
return e.RawApiResponse
}
// GetRawError GetRawApiResponse this get api raw response from midtrans backend
func (e *Error) GetRawError() error {
return e.RawError
}