Add OcrError type for the Rust OCR engine

This commit is contained in:
Ishaan Jaffer 2026-06-16 20:47:26 -07:00
parent b88fcef57a
commit 1aad05b558
No known key found for this signature in database

34
litellm-rust/src/error.rs Normal file
View 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 {}