forked from Antipitch/orwell
-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.go
74 lines (60 loc) · 1.36 KB
/
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
72
73
74
package orwell
type (
// ValidationError struct
validationError struct {
error
fieldName string
jsonName string
msg string
}
// StructValidationError struct
structValidationError struct {
error
errors []error
}
// InternalError struct
internalError struct {
err error
}
)
// NewValidationError func
func NewValidationError(fieldName, jsonName, msg string) *validationError {
return &validationError{fieldName: fieldName, jsonName: jsonName, msg: msg}
}
func (e validationError) Error() string {
return e.msg
}
func (e validationError) FieldName() string {
return e.fieldName
}
func (e validationError) JSONName() string {
return e.jsonName
}
// SetFieldName func
func (e *validationError) SetFieldName(str string) {
e.fieldName = str
}
// SetJSONName func
func (e *validationError) SetJSONName(str string) {
e.jsonName = str
}
func NewStructValidationError() *structValidationError {
return &structValidationError{}
}
func (e structValidationError) Error() string {
return "Validation of struct returned errors"
}
func (e structValidationError) Len() int {
return len(e.errors)
}
func (e structValidationError) ValueAt(i int) error {
return e.errors[i]
}
func NewInternalError(err error) *internalError {
return &internalError{err: err}
}
func (e internalError) Error() string {
return e.err.Error()
}
func (e internalError) Throw() {
}