-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
41 lines (35 loc) · 1.22 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
package ws
import (
"fmt"
)
type SpxError struct {
Code int `json:"code"`
Text string `json:"text"`
Detail string `json:"error"`
}
// Implement error interface
func (e SpxError) Error() string {
msg := fmt.Sprintf("Error code: %d, msg: %s, detail: %s", e.Code, e.Text, e.Detail)
return msg
}
// Only use a small set of HTTP error codes
//
// 200 - StatusOK
// 400 - StatusBadRequest
// 401 - StatusUnauthorized
// 403 - StatusForbidden
// 404 - StatusNotFound
// 500 - StatusInternalServerError
var (
ErrorHttpTimeout = SpxError{100, "we did not get a response from the server.", "http timeout"}
ErrorJWTInvalid = SpxError{101, "invalid API security credentials", "missing or invalid jwt access token"}
ErrorInvalidRequest = SpxError{102, "unexpected request parameters", "invalid parameters"}
ErrorTimeout = SpxError{103, "operation timeout", "operation timeout"}
ErrorClosed = SpxError{104, "socket closed", "underlying fd/socket closed normally"}
ErrorInternal = SpxError{999, "unexpected error", "internal error"}
)
// TODO: Adderror should return a new error with the added extension
func (e SpxError) AddError(err error) SpxError {
e.Detail = e.Detail + "; " + err.Error()
return e
}