-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherror.go
55 lines (46 loc) · 1.06 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
52
53
54
55
package biteship
import (
"encoding/json"
"log"
"net/http"
)
type Error struct {
Status int `json:"status,omitempty"`
ErrorCode string `json:"error_code,omitempty"`
Message string `json:"message,omitempty"`
RawError string `json:"error,omitempty"`
Code int `json:"code,omitempty"`
//RawApiResponse *ApiResponse `json:"raw_api_response,omitempty"`
}
//func (e *Error) Error() string {
// return e.Message
//}
func (e *Error) GetStatus() int {
return e.Status
}
func ErrorGo(err error) *Error {
return &Error{
Status: http.StatusInternalServerError,
ErrorCode: "Error Go",
Message: err.Error(),
}
}
func ErrorBiteship(err *Error) *Error {
return err
}
func ErrorRequestParam(err error) *Error {
return &Error{
Status: http.StatusBadRequest,
ErrorCode: "Bad Request",
Message: err.Error(),
}
}
func ErrorHttp(status int, respBody []byte) *Error {
var httpError *Error
if err := json.Unmarshal(respBody, &httpError); err != nil {
log.Println(err)
return ErrorGo(err)
}
httpError.Status = status
return httpError
}