-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_helper.go
50 lines (40 loc) · 1.76 KB
/
error_helper.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
package httperror
import (
"net/http"
)
// NewBadRequest returns a new error with status code 400.
func NewBadRequest(err interface{}, options ...ErrorOption) error {
return NewError(err, http.StatusBadRequest, options...)
}
// NewInternalServerError returns a new error with status code 500.
func NewInternalServerError(err interface{}, options ...ErrorOption) error {
return NewError(err, http.StatusInternalServerError, options...)
}
// NewNotFound returns a new error with status code 404.
func NewNotFound(err interface{}, options ...ErrorOption) error {
return NewError(err, http.StatusNotFound, options...)
}
// NewUnauthorized returns a new error with status code 401.
func NewUnauthorized(err interface{}, options ...ErrorOption) error {
return NewError(err, http.StatusUnauthorized, options...)
}
// NewForbidden returns a new error with status code 403.
func NewForbidden(err interface{}, options ...ErrorOption) error {
return NewError(err, http.StatusForbidden, options...)
}
// NewConflict returns a new error with status code 409.
func NewConflict(err interface{}, options ...ErrorOption) error {
return NewError(err, http.StatusConflict, options...)
}
// NewNotImplemented returns a new error with status code 501.
func NewNotImplemented(err interface{}, options ...ErrorOption) error {
return NewError(err, http.StatusNotImplemented, options...)
}
// NewMethodNotAllowed returns a new error with status code 405.
func NewMethodNotAllowed(err interface{}, options ...ErrorOption) error {
return NewError(err, http.StatusMethodNotAllowed, options...)
}
// NewUnprocessableEntity returns a new error with status code 422.
func NewUnprocessableEntity(err interface{}, options ...ErrorOption) error {
return NewError(err, http.StatusUnprocessableEntity, options...)
}