-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror.go
More file actions
47 lines (38 loc) · 1.15 KB
/
error.go
File metadata and controls
47 lines (38 loc) · 1.15 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
package msgcat
// Error is the catalog error type. When ErrorCode() is empty, use ErrorKey() as the API identifier.
type Error interface {
Error() string
Unwrap() error
ErrorCode() string // Optional; user-defined. Empty when not set. Use ErrorKey() when empty.
ErrorKey() string // Message key (e.g. "error.not_found"); use as identifier when ErrorCode() is empty.
GetShortMessage() string
GetLongMessage() string
}
type DefaultError struct {
err error
shortMessage string
longMessage string
code string
key string
}
func (ce DefaultError) Error() string {
return ce.shortMessage
}
func (ce *DefaultError) Unwrap() error {
return ce.err
}
func (ce *DefaultError) ErrorCode() string {
return ce.code
}
func (ce *DefaultError) ErrorKey() string {
return ce.key
}
func (ce *DefaultError) GetShortMessage() string {
return ce.shortMessage
}
func (ce *DefaultError) GetLongMessage() string {
return ce.longMessage
}
func newCatalogError(code string, key string, shortMessage string, longMessage string, err error) error {
return &DefaultError{shortMessage: shortMessage, longMessage: longMessage, code: code, key: key, err: err}
}