forked from eoscanada/eos-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
48 lines (42 loc) · 1.16 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
package eos
import (
"github.com/eoscanada/eos-go/eoserr"
)
// APIError represents the errors as reported by the server
type APIError struct {
Code int `json:"code"` // http code
Message string `json:"message"`
ErrorStruct struct {
Code int `json:"code"` // https://docs.google.com/spreadsheets/d/1uHeNDLnCVygqYK-V01CFANuxUwgRkNkrmeLm9MLqu9c/edit#gid=0
Name string `json:"name"`
What string `json:"what"`
Details []APIErrorDetail `json:"details"`
} `json:"error"`
}
func NewAPIError(httpCode int, msg string, e eoserr.Error) *APIError {
newError := &APIError{
Code: httpCode,
Message: msg,
}
newError.ErrorStruct.Code = e.Code
newError.ErrorStruct.Name = e.Name
newError.ErrorStruct.What = msg
newError.ErrorStruct.Details = []APIErrorDetail{
APIErrorDetail{
File: "",
LineNumber: 0,
Message: msg,
Method: e.Name,
},
}
return newError
}
type APIErrorDetail struct {
Message string `json:"message"`
File string `json:"file"`
LineNumber int `json:"line_number"`
Method string `json:"method"`
}
func (e APIError) Error() string {
return e.Message
}