forked from messagebird/go-rest-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
32 lines (27 loc) · 707 Bytes
/
error.go
File metadata and controls
32 lines (27 loc) · 707 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
package messagebird
import (
"fmt"
"strings"
)
// Error holds details including error code, human readable description and optional parameter that is related to the error.
type Error struct {
Code int
Description string
Parameter string
}
// Error implements error interface.
func (e Error) Error() string {
return e.Description
}
// ErrorResponse represents errored API response.
type ErrorResponse struct {
Errors []Error `json:"errors"`
}
// Error implements error interface.
func (r ErrorResponse) Error() string {
var inners []string
for _, inner := range r.Errors {
inners = append(inners, inner.Error())
}
return fmt.Sprintf("API errors: %s", strings.Join(inners, ", "))
}