openai/openai-go
Publicmirrored from https://github.com/openai/openai-goAvailable
auth/error.go
37lines · modecode
| 1 | package auth |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "github.com/openai/openai-go/v3/shared" |
| 7 | ) |
| 8 | |
| 9 | // SubjectTokenProviderError is raised when failing to get the subject token from the cloud environment. |
| 10 | type SubjectTokenProviderError struct { |
| 11 | Provider string |
| 12 | Message string |
| 13 | Cause error |
| 14 | } |
| 15 | |
| 16 | func (e *SubjectTokenProviderError) Error() string { |
| 17 | if e.Cause != nil { |
| 18 | return fmt.Sprintf("%s provider error: %s: %v", e.Provider, e.Message, e.Cause) |
| 19 | } |
| 20 | return fmt.Sprintf("%s provider error: %s", e.Provider, e.Message) |
| 21 | } |
| 22 | |
| 23 | func (e *SubjectTokenProviderError) Unwrap() error { |
| 24 | return e.Cause |
| 25 | } |
| 26 | |
| 27 | // OAuthError is raised when there is an error in the RFC-defined OAuth flow, such as failing to exchange the token. |
| 28 | // See https://datatracker.ietf.org/doc/html/rfc8693 for the OAuth 2.0 Token Exchange specification. |
| 29 | type OAuthError struct { |
| 30 | StatusCode int |
| 31 | ErrorCode shared.OAuthErrorCode |
| 32 | ErrorDescription string |
| 33 | } |
| 34 | |
| 35 | func (e *OAuthError) Error() string { |
| 36 | return fmt.Sprintf("OAuth error (status %d): %s - %s", e.StatusCode, e.ErrorCode, e.ErrorDescription) |
| 37 | } |
| 38 | |