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);