From 1aad05b558ac2b397a05b25e9532338a5148aa24 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Tue, 16 Jun 2026 20:47:26 -0700 Subject: [PATCH] Add OcrError type for the Rust OCR engine --- litellm-rust/src/error.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 litellm-rust/src/error.rs diff --git a/litellm-rust/src/error.rs b/litellm-rust/src/error.rs new file mode 100644 index 00000000000..c20dec0274f --- /dev/null +++ b/litellm-rust/src/error.rs @@ -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 {}