forked from ggicci/httpin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
83 lines (67 loc) · 2.42 KB
/
errors.go
File metadata and controls
83 lines (67 loc) · 2.42 KB
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
77
78
79
80
81
82
83
package httpin
import (
"errors"
"fmt"
"reflect"
)
var (
ErrMissingField = errors.New("missing required field")
ErrUnsupporetedType = errors.New("unsupported type")
ErrUnregisteredExecutor = errors.New("unregistered executor")
ErrDuplicateTypeDecoder = errors.New("duplicate type decoder")
ErrDuplicateNamedDecoder = errors.New("duplicate named decoder")
ErrNilTypeDecoder = errors.New("nil type decoder")
ErrInvalidTypeDecoder = errors.New("invalid type decoder")
ErrDuplicateExecutor = errors.New("duplicate executor")
ErrReservedExecutorName = errors.New("reserved executor name")
ErrNilExecutor = errors.New("nil executor")
ErrUnknownBodyType = errors.New("unknown body type")
ErrDuplicateAnnotationField = errors.New("duplicate annotation field")
ErrNilErrorHandler = errors.New("nil error handler")
ErrMaxMemoryTooSmall = errors.New("max memory too small")
ErrNilFile = errors.New("nil file")
ErrDuplicateBodyDecoder = errors.New("duplicate body decoder")
ErrMissingDecoderName = errors.New("missing decoder name")
ErrDecoderNotFound = errors.New("decoder not found")
)
type UnsupportedTypeError struct {
Type reflect.Type
}
func (e UnsupportedTypeError) Error() string {
return fmt.Sprintf("unsupported type: %q", e.Type)
}
func (e UnsupportedTypeError) Unwrap() error {
return ErrUnsupporetedType
}
type InvalidFieldError struct {
// Field is the name of the field.
Field string `json:"field"`
// Source is the directive which causes the error.
// e.g. form, header, required, etc.
Source string `json:"source"`
// Value is the input data.
Value interface{} `json:"value"`
// internalError is the underlying error thrown by the directive executor.
internalError error
// ErrorMessage is the string representation of `internalError`.
ErrorMessage string `json:"error"`
// directives is the list of directives bound to the field.
Directives []*Directive `json:"-"`
}
func (f *InvalidFieldError) Error() string {
return fmt.Sprintf("invalid field %q: %v", f.Field, f.internalError)
}
func (f *InvalidFieldError) Unwrap() error {
return f.internalError
}
type fieldError struct {
Key string
Value interface{}
internalError error
}
func (e fieldError) Error() string {
return e.internalError.Error()
}
func (e fieldError) Unwrap() error {
return e.internalError
}