pub enum OpenAIError {
ConfigError(String),
HTTPError(Error),
DeserializeError(Error),
APIError {
message: String,
err_type: Option<String>,
code: Option<String>,
},
IOError(Error),
}
Expand description
Represents any error that can occur while using the OpenAI Rust client library.
This enum covers:
- Configuration errors, such as missing API keys or invalid builder settings.
- Network/HTTP errors encountered while making requests.
- Errors returned by the OpenAI API itself (e.g., rate limits, invalid parameters).
- JSON parsing errors (e.g., unexpected response formats).
- IO errors that might occur during operations like file handling.
Variants§
ConfigError(String)
Errors related to invalid configuration or missing environment variables.
HTTPError(Error)
Errors returned by the underlying HTTP client (reqwest
).
This typically indicates network-level issues, timeouts, TLS errors, etc.
DeserializeError(Error)
Errors that happen due to invalid or unexpected responses from the OpenAI API.
For instance, if the response body is not valid JSON or doesn’t match the expected schema.
APIError
Errors reported by the OpenAI API in its response body.
This might include invalid request parameters, rate-limit violations, or internal server errors. The attached string typically contains a more descriptive message returned by the API.
Fields
IOError(Error)
Errors that occur during I/O operations.
Implementations§
Source§impl OpenAIError
impl OpenAIError
Sourcepub fn api_error(
message: impl Into<String>,
err_type: Option<&str>,
code: Option<&str>,
) -> Self
pub fn api_error( message: impl Into<String>, err_type: Option<&str>, code: Option<&str>, ) -> Self
Creates an OpenAIError::APIError
from detailed information about the error.
§Parameters
message
- A short description of the error.err_type
- The error type from OpenAI (e.g., “invalid_request_error”).code
- An optional error code from OpenAI.
§Example
use chat_gpt_lib_rs::OpenAIError;
let api_err = OpenAIError::api_error("Invalid request", Some("invalid_request_error"), None);
Trait Implementations§
Source§impl Debug for OpenAIError
impl Debug for OpenAIError
Source§impl Display for OpenAIError
impl Display for OpenAIError
Source§impl Error for OpenAIError
impl Error for OpenAIError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<Error> for OpenAIError
impl From<Error> for OpenAIError
Source§impl From<Error> for OpenAIError
impl From<Error> for OpenAIError
Auto Trait Implementations§
impl Freeze for OpenAIError
impl !RefUnwindSafe for OpenAIError
impl Send for OpenAIError
impl Sync for OpenAIError
impl Unpin for OpenAIError
impl !UnwindSafe for OpenAIError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.