-
Notifications
You must be signed in to change notification settings - Fork 18
/
errors.go
51 lines (38 loc) · 1.14 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
50
51
package main
import "net/http"
type apiError struct {
Code int `json:"code"`
Status string `json:"status"`
Message string `json:"message"`
}
func newApiError(code int, message string) *apiError {
return &apiError{
Code: code,
Status: http.StatusText(code),
Message: message,
}
}
func wrapError(err error) *apiError {
return newApiError(http.StatusInternalServerError,
err.Error())
}
func (a *apiError) Write(w http.ResponseWriter) {
w.WriteHeader(a.Code)
printError(w, a)
}
var errInvalidDir = newApiError(http.StatusBadRequest,
"Invalid Directory")
var errDirNotFound = newApiError(http.StatusNotFound,
"Directory does not exist")
var errPageNotFound = newApiError(http.StatusNotFound,
"Page does not exist")
var errMalformedJson = newApiError(http.StatusBadRequest,
"Could not parse request body")
var errDirConflict = newApiError(http.StatusConflict,
"Directory already exists")
var errNoMeta = newApiError(http.StatusBadRequest,
"page[meta] not sent in request")
var errInvalidJson = newApiError(http.StatusBadRequest,
"Malformed JSON")
var errNoConfig = newApiError(http.StatusNotFound,
"Could not find config file")