generated from bool64/go-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.go
47 lines (37 loc) · 985 Bytes
/
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
package jsonrpc
import (
"sort"
"github.com/swaggest/usecase/status"
)
// ErrWithFields exposes structured context of error.
type ErrWithFields interface {
error
Fields() map[string]interface{}
}
// ErrWithAppCode exposes application error code.
type ErrWithAppCode interface {
error
AppErrCode() int
}
// ErrWithCanonicalStatus exposes canonical status code.
type ErrWithCanonicalStatus interface {
error
Status() status.Code
}
// ValidationErrors is a list of validation errors.
//
// Key is field position (e.g. "path:id" or "body"), value is a list of issues with the field.
type ValidationErrors map[string][]string
// Error returns error message.
func (re ValidationErrors) Error() string {
return "validation failed"
}
// Fields returns request errors by field location and name.
func (re ValidationErrors) Fields() map[string]interface{} {
res := make(map[string]interface{}, len(re))
for k, v := range re {
sort.Strings(v)
res[k] = v
}
return res
}