-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
76 lines (60 loc) · 1.82 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package function
import (
"errors"
"fmt"
"net/http"
"github.com/ungerik/go-httpx/httperr"
)
var (
// ErrTypeNotSupported indicates that a type is not supported
ErrTypeNotSupported = errors.New("type not supported")
// HandleErrorHTTP will handle a non nil error by writing it to the response.
// The default is to use github.com/ungerik/go-httpx/httperr.DefaultHandler.
HandleErrorHTTP = func(err error, response http.ResponseWriter, request *http.Request) {
if err != nil {
httperr.DefaultHandler.HandleError(err, response, request)
}
}
)
type ErrParseArgString struct {
Err error
Func fmt.Stringer
Arg string
}
func NewErrParseArgString(err error, f fmt.Stringer, arg string) ErrParseArgString {
return ErrParseArgString{Err: err, Func: f, Arg: arg}
}
func (e ErrParseArgString) Error() string {
return fmt.Sprintf("string conversion error for argument %s of function %s: %s", e.Arg, e.Func, e.Err)
}
func (e ErrParseArgString) Unwrap() error {
return e.Err
}
type ErrParseArgJSON struct {
Err error
Func fmt.Stringer
Arg string
}
func NewErrParseArgJSON(err error, f fmt.Stringer, arg string) ErrParseArgJSON {
return ErrParseArgJSON{Err: err, Func: f, Arg: arg}
}
func (e ErrParseArgJSON) Error() string {
return fmt.Sprintf("error unmarshalling JSON for argument %s of function %s: %s", e.Arg, e.Func, e.Err)
}
func (e ErrParseArgJSON) Unwrap() error {
return e.Err
}
type ErrParseArgsJSON struct {
Err error
Func fmt.Stringer
JSON string
}
func NewErrParseArgsJSON(err error, f fmt.Stringer, argsJSON []byte) ErrParseArgsJSON {
return ErrParseArgsJSON{Err: err, Func: f, JSON: string(argsJSON)}
}
func (e ErrParseArgsJSON) Error() string {
return fmt.Sprintf("error unmarshalling JSON object for arguments of function %s: %s", e.Func, e.Err)
}
func (e ErrParseArgsJSON) Unwrap() error {
return e.Err
}