forked from sashabaranov/go-openai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
37 lines (30 loc) · 772 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
package openai
import "fmt"
// APIError provides error information returned by the OpenAI API.
type APIError struct {
Code *string `json:"code,omitempty"`
Message string `json:"message"`
Param *string `json:"param,omitempty"`
Type string `json:"type"`
StatusCode int `json:"-"`
}
// RequestError provides informations about generic request errors.
type RequestError struct {
StatusCode int
Err error
}
type ErrorResponse struct {
Error *APIError `json:"error,omitempty"`
}
func (e *APIError) Error() string {
return e.Message
}
func (e *RequestError) Error() string {
if e.Err != nil {
return e.Err.Error()
}
return fmt.Sprintf("status code %d", e.StatusCode)
}
func (e *RequestError) Unwrap() error {
return e.Err
}