-
Notifications
You must be signed in to change notification settings - Fork 1
/
fieldErrors.go
228 lines (186 loc) · 9.24 KB
/
fieldErrors.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package wire
import (
"errors"
"fmt"
)
var (
// Errors specific to validation
// ErrValidTagForType is returned when a type has an invalid tag
ErrValidTagForType = errors.New("is an invalid tag")
// ErrNonNumeric is returned when a field has non-numeric characters
ErrNonNumeric = errors.New("has non numeric characters")
// ErrNonAlphanumeric is returned when a field has non-alphanumeric characters
ErrNonAlphanumeric = errors.New("has non alphanumeric characters")
// ErrNonAmount is returned for an incorrect wire amount format
ErrNonAmount = errors.New("is an incorrect amount format")
// ErrNonCurrencyCode is returned for an incorrect currency code
ErrNonCurrencyCode = errors.New("is not a recognized currency code")
// ErrUpperAlpha is returned when a field is not in uppercase
ErrUpperAlpha = errors.New("is not uppercase A-Z or 0-9")
// ErrFieldInclusion is returned when a field is mandatory and has a default value
ErrFieldInclusion = errors.New("is a mandatory field and has a default value")
// ErrConstructor is returned when there's a mandatory field is not initialized correctly, and prompts to use the constructor
ErrConstructor = errors.New("is a mandatory field and has a default value. Use the constructor")
// ErrFieldRequired is returned when a field is required
ErrFieldRequired = errors.New("is a required field")
// ErrNotPermitted is returned when a field is included, but not permitted in combination with the other tags present in the message
ErrNotPermitted = errors.New("is not permitted in this context")
// ErrValidMonth is returned for an invalid month
ErrValidMonth = errors.New("is an invalid month")
// ErrValidDay is returned for an invalid day
ErrValidDay = errors.New("is an invalid day")
// ErrValidYear is returned for an invalid year
ErrValidYear = errors.New("is an invalid year")
// ErrValidCentury is returned for an invalid century
ErrValidCentury = errors.New("is an invalid century")
// ErrValidDate is returned for an invalid date
ErrValidDate = errors.New("is an invalid date format")
// ErrInvalidProperty is returned for an invalid type property
ErrInvalidProperty = errors.New("is an invalid property")
// SenderSupplied Tag {1500}
// ErrFormatVersion is returned for an invalid an invalid FormatVersion
ErrFormatVersion = errors.New("is not 30")
// ErrTestProductionCode is returned for an invalid TestProductionCode
ErrTestProductionCode = errors.New("is an invalid test production code")
// ErrMessageDuplicationCode is returned for an invalid MessageDuplicationCode
ErrMessageDuplicationCode = errors.New("is an invalid message duplication code")
// TypeSubType Tag {1510}
// ErrTypeCode is returned for an invalid TypeCode tag
ErrTypeCode = errors.New("is an invalid type code")
// ErrSubTypeCode is returned when there's an invalid SubTypeCode tag
ErrSubTypeCode = errors.New("is an invalid sub type Code")
// BusinessFunctionCode Tag {3600}
// ErrBusinessFunctionCode is returned for an invalid business function code
ErrBusinessFunctionCode = errors.New("is an invalid business function code")
// ErrTransactionTypeCode is returned for an invalid transaction type code
ErrTransactionTypeCode = errors.New("is an invalid transaction type code")
// ErrLocalInstrumentNotPermitted is returned when LocalInstrument is included and BusinessFunctionCode is NOT CustomerTransferPlus
ErrLocalInstrumentNotPermitted = errors.New("is only permitted for business function code CTP")
// ErrLocalInstrumentCode is returned for an invalid local instrument code tag {3610}
ErrLocalInstrumentCode = errors.New("is an invalid local instrument Code")
// ErrPaymentNotificationIndicator is returned for an invalid payment notification indicator {3620}
ErrPaymentNotificationIndicator = errors.New("is an invalid payment notification indicator")
// Charges Tag {3700}
// ErrChargeDetails is returned for an invalid charge details for charges
ErrChargeDetails = errors.New("is an invalid charge detail")
// Beneficiary {4000}
// ErrIdentificationCode is returned for an invalid identification code
ErrIdentificationCode = errors.New("is an invalid identification code")
// ErrAdviceCode is returned for an invalid advice code
ErrAdviceCode = errors.New("is an invalid advice code")
// Related Remittance Information {8250}
// ErrRemittanceLocationMethod is returned for an invalid remittance location method
ErrRemittanceLocationMethod = errors.New("is an invalid remittance location method")
// ErrAddressType is returned for an invalid address type
ErrAddressType = errors.New("is an invalid address type")
// ErrIdentificationType is returned for an invalid remittance Identification Typ
ErrIdentificationType = errors.New("is an invalid remittance identification type")
// ErrOrganizationIdentificationCode is returned for an invalid organization identification code
ErrOrganizationIdentificationCode = errors.New("is an invalid organization identification code")
// ErrPrivateIdentificationCode is returned for an invalid private identification code
ErrPrivateIdentificationCode = errors.New("is an invalid private identification code")
// ErrDocumentTypeCode is returned for an invalid document type code
ErrDocumentTypeCode = errors.New("is an invalid document type code")
// ErrCreditDebitIndicator is returned for an invalid credit or debit indicator
ErrCreditDebitIndicator = errors.New("is an invalid credit or debit indicator")
// ErrAdjustmentReasonCode is returned for an invalid adjustment reason code
ErrAdjustmentReasonCode = errors.New("is an invalid adjustment reason code")
// ErrPartyIdentifier is returned for an invalid party identifier
ErrPartyIdentifier = errors.New("is an invalid party identifier")
// ErrOptionFLine is returned for an invalid line for OriginatorOptionF
ErrOptionFLine = errors.New("is an invalid line for originator optionF")
// ErrOptionFName is returned for an invalid name for OriginatorOptionF
ErrOptionFName = errors.New("is an invalid name for originator optionF")
)
// FieldError is returned for errors at a field level in a tag
type FieldError struct {
FieldName string // field name where error happened
Value interface{} // value that cause error
Err error // context of the error.
Msg string // deprecated
}
// Error message is constructed
func (e *FieldError) Error() string {
return fmt.Sprintf("%s %v %s", e.FieldName, e.Value, e.Err)
}
// Unwrap implements the base.UnwrappableError interface for FieldError
func (e *FieldError) Unwrap() error {
return e.Err
}
func fieldError(field string, err error, values ...interface{}) error {
if err == nil {
return nil
}
if _, ok := err.(*FieldError); ok {
return err
}
fe := FieldError{
FieldName: field,
Err: err,
}
// only the first value counts
if len(values) > 0 {
fe.Value = values[0]
}
return &fe
}
// ErrBusinessFunctionCodeProperty is the error given when the observed check digit does not match the calculated one
type ErrBusinessFunctionCodeProperty struct {
Message string
Property string
PropertyValue string
BusinessFunctionCode string
}
// NewErrBusinessFunctionCodeProperty creates a new error of the ErrBusinessFunctionCodeProperty type
func NewErrBusinessFunctionCodeProperty(property, propertyValue, businessFunctionCode string) ErrBusinessFunctionCodeProperty {
return ErrBusinessFunctionCodeProperty{
Message: fmt.Sprintf("%v: %v is not valid for %v", property, propertyValue, businessFunctionCode),
Property: property,
PropertyValue: propertyValue,
BusinessFunctionCode: businessFunctionCode,
}
}
func (e ErrBusinessFunctionCodeProperty) Error() string {
return e.Message
}
// ErrInvalidPropertyForProperty is the error given when the observed check digit does not match the calculated one
type ErrInvalidPropertyForProperty struct {
Message string
Property string
PropertyValue string
SecondProperty string
SecondPropertyValue string
}
// NewErrInvalidPropertyForProperty creates a new error of the ErrInvalidPropertyForProperty type
func NewErrInvalidPropertyForProperty(property, propertyValue, secondProperty, secondPropertyValue string) ErrInvalidPropertyForProperty {
return ErrInvalidPropertyForProperty{
Message: fmt.Sprintf("%v: %v is not valid for %v: %v", property, propertyValue, secondProperty, secondPropertyValue),
Property: property,
PropertyValue: propertyValue,
SecondProperty: secondProperty,
SecondPropertyValue: secondPropertyValue,
}
}
func (e ErrInvalidPropertyForProperty) Error() string {
return e.Message
}
// FieldWrongLengthErr is the error given when a Field is the wrong length
type FieldWrongLengthErr struct {
Message string
FieldLength int
Length int
}
// NewFieldWrongLengthErr creates a new error of the FieldWrongLengthErr type
func NewFieldWrongLengthErr(FieldLength, length int) FieldWrongLengthErr {
return FieldWrongLengthErr{
Message: fmt.Sprintf("must be %d characters and found %d", FieldLength, length),
FieldLength: FieldLength,
Length: length,
}
}
func (e FieldWrongLengthErr) Error() string {
return e.Message
}