-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patherror.go
More file actions
32 lines (27 loc) · 759 Bytes
/
error.go
File metadata and controls
32 lines (27 loc) · 759 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 openai
import (
"fmt"
"net/http"
)
type wrappedError struct {
Err *Error `json:"error"`
}
// Error represents an error response from the API.
type Error struct {
StatusCode int `json:"statusCode"`
Code string `json:"code"`
Message string `json:"message"`
Param *string `json:"param,omitempty"`
Type string `json:"type"`
}
// Error implements the error interface.
func (e *Error) Error() string {
return fmt.Sprintf("Code: %v, Message: %s, Type: %s, Param: %v", e.Code, e.Message, e.Type, e.Param)
}
// Retryable returns true if the error is retryable.
func (e *Error) Retryable() bool {
if e.StatusCode >= http.StatusInternalServerError {
return true
}
return e.StatusCode == http.StatusTooManyRequests
}