-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathframework_response_error.go
71 lines (64 loc) · 3.17 KB
/
framework_response_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
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
package gimlet
import (
"net/http"
)
// MakeTextErrorResponder takes an error object and converts
// it into a responder object that wrap's gimlet's ErrorResponse
// type. Since ErrorResponse implements the error interface, if you
// pass an ErrorResposne object, this function will propagate the
// status code specified in the ErrorResponse if that code is valid,
// otherwise the status code of the request and the response object
// will be 400.
func MakeTextErrorResponder(err error) Responder {
return newResponder(err, http.StatusBadRequest, TEXT)
}
// MakeJSONErrorResponder takes an error object and converts
// it into a responder object that wrap's gimlet's ErrorResponse
// type. Since ErrorResponse implements the error interface, if you
// pass an ErrorResposne object, this function will propagate the
// status code specified in the ErrorResponse if that code is valid,
// otherwise the status code of the request and the response object
// will be 400.
func MakeJSONErrorResponder(err error) Responder {
return newResponder(err, http.StatusBadRequest, JSON)
}
// MakeYAMLErrorResponder takes an error object and converts
// it into a responder object that wrap's gimlet's ErrorResponse
// type. Since ErrorResponse implements the error interface, if you
// pass an ErrorResposne object, this function will propagate the
// status code specified in the ErrorResponse if that code is valid,
// otherwise the status code of the request and the response object
// will be 400.
func MakeYAMLErrorResponder(err error) Responder {
return newResponder(err, http.StatusBadRequest, YAML)
}
// MakeTextInternalErrorResponder takes an error object and converts
// it into a responder object that wrap's gimlet's ErrorResponse
// type. Since ErrorResponse implements the error interface, if you
// pass an ErrorResposne object, this function will propagate the
// status code specified in the ErrorResponse if that code is valid,
// otherwise the status code of the request and the response object
// will be 500.
func MakeTextInternalErrorResponder(err error) Responder {
return newResponder(err, http.StatusInternalServerError, TEXT)
}
// MakeJSONInternalErrorResponder takes an error object and converts
// it into a responder object that wrap's gimlet's ErrorResponse
// type. Since ErrorResponse implements the error interface, if you
// pass an ErrorResposne object, this function will propagate the
// status code specified in the ErrorResponse if that code is valid,
// otherwise the status code of the request and the response object
// will be 500.
func MakeJSONInternalErrorResponder(err error) Responder {
return newResponder(err, http.StatusInternalServerError, JSON)
}
// MakeYAMLInternalErrorResponder takes an error object and converts
// it into a responder object that wrap's gimlet's ErrorResponse
// type. Since ErrorResponse implements the error interface, if you
// pass an ErrorResposne object, this function will propagate the
// status code specified in the ErrorResponse if that code is valid,
// otherwise the status code of the request and the response object
// will be 500.
func MakeYAMLInternalErrorResponder(err error) Responder {
return newResponder(err, http.StatusInternalServerError, YAML)
}