This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvalidation_errors.go
72 lines (57 loc) · 1.61 KB
/
validation_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
package api
import (
"fmt"
"github.com/Worldcoin/hubble-commander/utils"
)
var (
AnyMissingFieldError, anyMissingFieldErrorSupport = utils.NewAnyError(&MissingFieldError{})
AnyInvalidSignatureError, anyInvalidSignatureErrorSupport = utils.NewAnyError(&InvalidSignatureError{})
)
type MissingFieldError struct {
*utils.AnyErrorSupport
field string
}
func NewMissingFieldError(field string) *MissingFieldError {
return &MissingFieldError{
AnyErrorSupport: anyMissingFieldErrorSupport,
field: field,
}
}
func (e *MissingFieldError) Unwrap() error {
return e.AnyErrorSupport
}
func (e *MissingFieldError) Error() string {
return fmt.Sprintf("missing required %s field", e.field)
}
type NotDecimalEncodableError struct {
field string
}
func NewNotDecimalEncodableError(field string) *NotDecimalEncodableError {
return &NotDecimalEncodableError{field: field}
}
func (e NotDecimalEncodableError) Error() string {
return fmt.Sprintf("%s is not encodable as multi-precission decimal", e.field)
}
func (e *NotDecimalEncodableError) Is(other error) bool {
otherError, ok := other.(*NotDecimalEncodableError)
if !ok {
return false
}
return *e == *otherError
}
type InvalidSignatureError struct {
*utils.AnyErrorSupport
reason string
}
func NewInvalidSignatureError(reason string) *InvalidSignatureError {
return &InvalidSignatureError{
AnyErrorSupport: anyInvalidSignatureErrorSupport,
reason: reason,
}
}
func (e *InvalidSignatureError) Unwrap() error {
return e.AnyErrorSupport
}
func (e *InvalidSignatureError) Error() string {
return fmt.Sprintf("invalid signature: %s", e.reason)
}