-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
49 lines (42 loc) · 1.21 KB
/
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 serve
import (
"net/http"
"github.com/TosinShada/stellar-core/support/render/httpjson"
)
var serverError = errorResponse{
Status: http.StatusInternalServerError,
Error: "An error occurred while processing this request.",
}
var notFound = errorResponse{
Status: http.StatusNotFound,
Error: "The resource at the url requested was not found.",
}
var methodNotAllowed = errorResponse{
Status: http.StatusMethodNotAllowed,
Error: "The method is not allowed for resource at the url requested.",
}
var badRequest = errorResponse{
Status: http.StatusBadRequest,
Error: "The request was invalid in some way.",
}
var conflict = errorResponse{
Status: http.StatusConflict,
Error: "The request could not be completed because the resource already exists.",
}
var unauthorized = errorResponse{
Status: http.StatusUnauthorized,
Error: "The request could not be authenticated.",
}
type errorResponse struct {
Status int `json:"-"`
Error string `json:"error"`
}
func (e errorResponse) Render(w http.ResponseWriter) {
httpjson.RenderStatus(w, e.Status, e, httpjson.JSON)
}
type errorHandler struct {
Error errorResponse
}
func (h errorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.Error.Render(w)
}