-
Notifications
You must be signed in to change notification settings - Fork 16
/
errors.go
61 lines (45 loc) · 2.28 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
package address
import (
"errors"
"fmt"
"strings"
)
// ErrInvalidCountryCode indicate that the country code used to create an address is invalid.
var ErrInvalidCountryCode = errors.New("invalid country code")
// ErrInvalidDependentLocality indicates that the dependent locality is invalid. This is usually due to the country having
// a pre-determined list of dependent localities and the value does not match any of the keys in the list of dependent localities.
var ErrInvalidDependentLocality = errors.New("invalid dependent locality")
// ErrInvalidLocality indicates that the locality is invalid. This is usually due to the country having
// a pre-determined list of localities and the value does not match any of the keys in the list of localities.
var ErrInvalidLocality = errors.New("invalid locality")
// ErrInvalidAdministrativeArea indicates that the administrative area is invalid. This is usually due to the country having
// a pre-determined list of administrative areas and the value does not match any of the keys in the list of administrative areas.
var ErrInvalidAdministrativeArea = errors.New("invalid administrative area")
// ErrInvalidPostCode indicates that the post code did not valid using the regular expressions of the country.
var ErrInvalidPostCode = errors.New("invalid post code")
// ErrMissingRequiredFields indicates the a required address field is missing. The Fields field can be used to get a list
// of missing fields.
type ErrMissingRequiredFields struct {
country string
Fields []Field
}
func (e ErrMissingRequiredFields) Error() string {
var fieldsStr []string
for _, field := range e.Fields {
fieldsStr = append(fieldsStr, field.String())
}
return fmt.Sprintf("missing required fields for %s: %s", e.country, strings.Join(fieldsStr, ","))
}
// ErrUnsupportedFields indicates that an address field as provided, but it is not supported by the address format
// of the country. The Fields field can be used to get a list of unsupported fields.
type ErrUnsupportedFields struct {
country string
Fields []Field
}
func (e ErrUnsupportedFields) Error() string {
var fieldsStr []string
for _, field := range e.Fields {
fieldsStr = append(fieldsStr, field.String())
}
return fmt.Sprintf("unsupported fields for %s: %s", e.country, strings.Join(fieldsStr, ","))
}