-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
49 lines (41 loc) · 892 Bytes
/
errors.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
package errs
import "net/http"
type AppError struct {
Code int `json:",omitempty"`
Message string `json:"message"`
}
func NewNotFoundError(message string) *AppError {
return &AppError{
Message: message,
Code: http.StatusNotFound,
}
}
func NewUnexpectedError(message string) *AppError {
return &AppError{
Message: message,
Code: http.StatusInternalServerError,
}
}
func NewValidationError(message string) *AppError {
return &AppError{
Message: message,
Code: http.StatusUnprocessableEntity,
}
}
func NewAuthenticatonError(message string) *AppError {
return &AppError{
Message: message,
Code: http.StatusUnauthorized,
}
}
func NewAuthorizationError(message string) *AppError {
return &AppError{
Message: message,
Code: http.StatusForbidden,
}
}
func (a AppError) AsMessage() *AppError {
return &AppError{
Message: a.Message,
}
}