forked from go-chi/chi
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.go
More file actions
78 lines (68 loc) · 1.65 KB
/
errors.go
File metadata and controls
78 lines (68 loc) · 1.65 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package phi
var (
writingError = Error{
Error: "writingError",
Message: "error while writing response",
}
parseError = Error{
Error: "parseError",
Message: "error while parsing response",
}
decodingError = Error{
Error: "decodingError",
Message: "error while decoding request body",
}
)
type Error struct {
Error string
Message string
StatusCode int
}
// Validation error can be used for validating post bodies
func ValidatingError(e error) *Error {
return &Error{
Error: "validatingError",
Message: e.Error(),
StatusCode: 400,
}
}
// Parameter error for error handling regarding parameter missing /yeet/{cid} -> cid = parameter
func URLParameterError(e string) *Error {
return &Error{
Error: "missingURLParameters",
Message: e,
StatusCode: 400,
}
}
// Query Parameter error for error handling regarding parameter missing /yeet?id=1337 -> id = query parameter
func QueryParameterError(e string) *Error {
return &Error{
Error: "missingQueryParameters",
Message: e,
StatusCode: 400,
}
}
// Body Parameter error for error handling regarding parameter missing POST body = { "data": "123"} -> data = body parameter
func BodyParameterError(e string) *Error {
return &Error{
Error: "missingBodyParameters",
Message: e,
StatusCode: 400,
}
}
// Unknown error for generic error handling
func UnknownError(e error) *Error {
return &Error{
Error: "unknownError",
Message: e.Error(),
StatusCode: 500,
}
}
// Unauthorized error + statuscode 401
func Unauthorized() *Error {
return &Error{
Error: "unauthorized",
Message: "invalid token",
StatusCode: 401,
}
}