-
Notifications
You must be signed in to change notification settings - Fork 44
/
error.go
51 lines (41 loc) · 1.36 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
46
47
48
49
50
51
package omise
import (
"errors"
"strconv"
)
// ErrInvalidKey represents missing or bad API key errors.
var ErrInvalidKey = errors.New("invalid public or secret key")
// ErrInternal represents internal library error. If you encounter this, it is mostly
// likely due to a bug in the omise-go library itself. Please report it by opening a new
// GitHub issue or contacting support.
type ErrInternal string
func (err ErrInternal) Error() string {
return "internal inconsistency: " + string(err)
}
// ErrTransport wraps error returned by omise-go internal HTTP transport implementation.
type ErrTransport struct {
Err error
Buffer []byte
}
func (err ErrTransport) Error() string {
return "transport error: " + err.Err.Error() +
"\n with response body: " + string(err.Buffer)
}
// Error struct represents errors that may be returned from Omise's REST API. You can use
// the Code or the HTTP StatusCode field to test for the exact error condition in your
// code.
type Error struct {
Location string `json:"location"`
StatusCode int `json:"status"`
Code string `json:"code"`
Message string `json:"message"`
}
func (err *Error) String() string {
if err.StatusCode == 0 {
return "(" + err.Code + ") " + err.Message
}
return "(" + strconv.Itoa(err.StatusCode) + "/" + err.Code + ") " + err.Message
}
func (err *Error) Error() string {
return err.String()
}