-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
45 lines (36 loc) · 1.45 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
package res
import (
"net/http"
"go.bobheadxi.dev/res/base"
)
// ErrResponse is the template for a typical HTTP response for errors
type ErrResponse struct {
*base.Response
}
// Err is a basic error response constructor
func Err(message string, code int, kvs ...interface{}) *ErrResponse {
return &ErrResponse{base.NewResponse(message, code, kvs)}
}
// ErrInternalServer is a shortcut for internal server errors. It should be
// accompanied by an actual error.
func ErrInternalServer(message string, err error, kvs ...interface{}) *ErrResponse {
var b = base.NewResponse(message, http.StatusInternalServerError, kvs)
b.Err = err.Error()
return &ErrResponse{b}
}
// ErrBadRequest is a shortcut for bad requests
func ErrBadRequest(message string, kvs ...interface{}) *ErrResponse {
return &ErrResponse{base.NewResponse(message, http.StatusBadRequest, kvs)}
}
// ErrUnauthorized is a shortcut for unauthorized requests
func ErrUnauthorized(message string, kvs ...interface{}) *ErrResponse {
return &ErrResponse{base.NewResponse(message, http.StatusUnauthorized, kvs)}
}
// ErrForbidden is a shortcut for forbidden requests
func ErrForbidden(message string, kvs ...interface{}) *ErrResponse {
return &ErrResponse{base.NewResponse(message, http.StatusForbidden, kvs)}
}
// ErrNotFound is a shortcut for forbidden requests
func ErrNotFound(message string, kvs ...interface{}) *ErrResponse {
return &ErrResponse{base.NewResponse(message, http.StatusNotFound, kvs)}
}