-
Notifications
You must be signed in to change notification settings - Fork 3
/
error.go
60 lines (55 loc) · 1.52 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
56
57
58
59
60
package handler
import "net/http"
type errorResponseCode int
const (
internalServerErrorCode errorResponseCode = iota + 1
invalidIDCode
malformedRequestBodyCode
requestValidationFailedCode
webhookNotFoundCode
deliveryNotFoundCode
deliveryAttemptNotFoundCode
)
var errorResponses = map[string]errorResponse{
"internal_server_error": {
Code: internalServerErrorCode,
Message: "internal server error",
StatusCode: http.StatusInternalServerError,
},
"invalid_id": {
Code: invalidIDCode,
Message: "invalid id",
StatusCode: http.StatusNotFound,
},
"malformed_request_body": {
Code: malformedRequestBodyCode,
Message: "malformed request body",
StatusCode: http.StatusBadRequest,
},
"request_validation_failed": {
Code: requestValidationFailedCode,
Message: "request validation failed",
StatusCode: http.StatusBadRequest,
},
"webhook_not_found": {
Code: webhookNotFoundCode,
Message: "webhook not found",
StatusCode: http.StatusNotFound,
},
"delivery_not_found": {
Code: deliveryNotFoundCode,
Message: "delivery not found",
StatusCode: http.StatusNotFound,
},
"delivery_attempt_not_found": {
Code: deliveryAttemptNotFoundCode,
Message: "delivery attempt not found",
StatusCode: http.StatusNotFound,
},
}
type errorResponse struct {
Code errorResponseCode `json:"code"`
Message string `json:"message"`
Details string `json:"details,omitempty"`
StatusCode int `json:"-"`
} //@name Error