forked from grafana-cold-storage/metrictank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
53 lines (44 loc) · 815 Bytes
/
Copy patherror.go
File metadata and controls
53 lines (44 loc) · 815 Bytes
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
package response
type Error interface {
Code() int
Error() string
}
type ErrorResp struct {
code int
err string
}
func WrapError(e error) *ErrorResp {
if _, ok := e.(*ErrorResp); ok {
return e.(*ErrorResp)
}
resp := &ErrorResp{
err: e.Error(),
code: 500,
}
if _, ok := e.(Error); ok {
resp.code = e.(Error).Code()
}
return resp
}
func NewError(code int, err string) *ErrorResp {
return &ErrorResp{
code: code,
err: err,
}
}
func (r *ErrorResp) Error() string {
return r.err
}
func (r *ErrorResp) Code() int {
return r.code
}
func (r *ErrorResp) Close() {
return
}
func (r *ErrorResp) Body() ([]byte, error) {
return []byte(r.err), nil
}
func (r *ErrorResp) Headers() (headers map[string]string) {
headers = map[string]string{"content-type": "text/plain"}
return headers
}