mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
Add OcrError type for the Rust OCR engine
This commit is contained in:
parent
b88fcef57a
commit
1aad05b558
1 changed files with 34 additions and 0 deletions
34
litellm-rust/src/error.rs
Normal file
34
litellm-rust/src/error.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
//! OCR error type. Pure: no PyO3.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
/// Errors that can occur while performing an OCR call.
|
||||
#[derive(Debug)]
|
||||
pub enum OcrError {
|
||||
/// Missing/invalid credentials or other env validation failure.
|
||||
Auth(String),
|
||||
/// A transform (request build or response parse) failed.
|
||||
Transform(String),
|
||||
/// Upstream returned a non-2xx status.
|
||||
Http { status: u16, body: String },
|
||||
/// Network-level failure (connection, timeout, etc.).
|
||||
Network(String),
|
||||
/// Failed to parse the upstream response body as JSON.
|
||||
Parse(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for OcrError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
OcrError::Auth(msg) => write!(f, "{msg}"),
|
||||
OcrError::Transform(msg) => write!(f, "{msg}"),
|
||||
OcrError::Http { status, body } => {
|
||||
write!(f, "Mistral OCR request failed with status {status}: {body}")
|
||||
}
|
||||
OcrError::Network(msg) => write!(f, "Mistral OCR network error: {msg}"),
|
||||
OcrError::Parse(msg) => write!(f, "Error parsing Mistral OCR response: {msg}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for OcrError {}
|
||||
Loading…
Add table
Reference in a new issue