-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
35 lines (30 loc) · 802 Bytes
/
error.go
File metadata and controls
35 lines (30 loc) · 802 Bytes
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
package voicebase
import "fmt"
type ErrorItem struct {
Error string `json:"error"`
}
type Message struct {
Code int `json:"code"`
Path string `json:"path"`
Message string `json:"message"`
}
// Error is a structured response indicating a non-2xx HTTP response.
type Error struct {
Warnings []Message `json:"warnings"`
Errors []ErrorItem `json:"errors"`
Reference string `json:"reference"`
Status int `json:"status"`
}
func (e *Error) Error() string {
errStr := fmt.Sprintf("voicebase: status=%d %s: ", e.Status, e.Reference)
for i, err := range e.Errors {
if i > 0 {
errStr += ", "
}
errStr += err.Error
}
for _, warn := range e.Warnings {
errStr += fmt.Sprintf(", warning (code %d @ %s): %s", warn.Code, warn.Path, warn.Message)
}
return errStr
}