-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy patherrors.go
49 lines (40 loc) · 1.3 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
package elevenlabs
import (
"fmt"
"strings"
)
// APIError represents an error response from the API.
//
// At this stage, any error that is not a ValidationError is returned in this format.
type APIError struct {
Detail APIErrorDetail `json:"detail"`
}
// APIErrorDetail contains detailed information about an APIError.
type APIErrorDetail struct {
Status string `json:"status"`
Message string `json:"message"`
AdditionalInfo string `json:"additional_info,omitempty"`
}
func (e *APIError) Error() string {
return fmt.Sprintf("api error - %s", e.Detail.Message)
}
// ValidationError represents a request validation error response from the API.
type ValidationError struct {
Detail *[]ValidationErrorDetailItem `json:"detail"`
}
type ValidationErrorDetailItem struct {
Loc []ValidationErrorDetailLocItem `json:"loc"`
Msg string `json:"msg"`
Type string `json:"type"`
}
type ValidationErrorDetailLocItem string
func (i *ValidationErrorDetailLocItem) UnmarshalJSON(b []byte) error {
*i = ValidationErrorDetailLocItem(strings.Trim(string(b), "\""))
return nil
}
func (e *ValidationError) Error() string {
if (*e).Detail != nil && len(*e.Detail) > 0 {
return fmt.Sprintf("validation error - %s", (*e.Detail)[0].Msg)
}
return "validation error"
}