-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy patherror_defaults.go
More file actions
94 lines (82 loc) · 2.77 KB
/
error_defaults.go
File metadata and controls
94 lines (82 loc) · 2.77 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package herodot
import (
"net/http"
"google.golang.org/grpc/codes"
)
func ErrNotFound() *DefaultError {
return &DefaultError{
StatusField: http.StatusText(http.StatusNotFound),
ErrorField: "The requested resource could not be found",
CodeField: http.StatusNotFound,
GRPCCodeField: codes.NotFound,
}
}
func ErrUnauthorized() *DefaultError {
return &DefaultError{
StatusField: http.StatusText(http.StatusUnauthorized),
ErrorField: "The request could not be authorized",
CodeField: http.StatusUnauthorized,
GRPCCodeField: codes.Unauthenticated,
}
}
func ErrForbidden() *DefaultError {
return &DefaultError{
StatusField: http.StatusText(http.StatusForbidden),
ErrorField: "The requested action was forbidden",
CodeField: http.StatusForbidden,
GRPCCodeField: codes.PermissionDenied,
}
}
func ErrInternalServerError() *DefaultError {
return &DefaultError{
StatusField: http.StatusText(http.StatusInternalServerError),
ErrorField: "An internal server error occurred, please contact the system administrator",
CodeField: http.StatusInternalServerError,
GRPCCodeField: codes.Internal,
}
}
func ErrBadRequest() *DefaultError {
return &DefaultError{
StatusField: http.StatusText(http.StatusBadRequest),
ErrorField: "The request was malformed or contained invalid parameters",
CodeField: http.StatusBadRequest,
GRPCCodeField: codes.InvalidArgument,
}
}
func ErrUnsupportedMediaType() *DefaultError {
return &DefaultError{
StatusField: http.StatusText(http.StatusUnsupportedMediaType),
ErrorField: "The request is using an unknown content type",
CodeField: http.StatusUnsupportedMediaType,
GRPCCodeField: codes.InvalidArgument,
}
}
func ErrConflict() *DefaultError {
return &DefaultError{
StatusField: http.StatusText(http.StatusConflict),
ErrorField: "The resource could not be created due to a conflict",
CodeField: http.StatusConflict,
GRPCCodeField: codes.FailedPrecondition,
}
}
func ErrMisconfiguration() *DefaultError {
return &DefaultError{
IDField: "invalid_configuration",
StatusField: http.StatusText(http.StatusInternalServerError),
ErrorField: "Invalid configuration",
ReasonField: "One or more configuration values are invalid. Please report this to the system administrator.",
CodeField: http.StatusInternalServerError,
GRPCCodeField: codes.Internal,
}
}
func ErrUpstreamError() *DefaultError {
return &DefaultError{
IDField: "upstream_error",
StatusField: http.StatusText(http.StatusBadGateway),
ErrorField: "Upstream error",
ReasonField: "An upstream server encountered an error or returned a malformed or unexpected response.",
CodeField: http.StatusBadGateway,
}
}