pub enum ClaudeApiError {
InvalidRequest {
message: String,
},
AuthenticationError {
message: String,
},
PermissionDenied {
message: String,
},
NotFound {
message: String,
},
RequestTooLarge {
message: String,
},
RateLimited {
message: String,
},
InternalError {
message: String,
},
Overloaded {
message: String,
},
Network(Error),
JsonParse(Error),
StreamError {
message: String,
},
Unknown {
status: u16,
message: String,
},
}Expand description
Every error the Claude Messages API can return, plus network/parse errors.
§Example
match err {
ClaudeApiError::RateLimited { message } => { /* back off and retry */ }
ClaudeApiError::InvalidRequest { message } => { /* fix request */ }
_ => { /* log and bail */ }
}Variants§
InvalidRequest
400 - Malformed JSON, missing params, invalid values
AuthenticationError
401 - Missing or invalid API key
PermissionDenied
403 - API key lacks permission for the requested model/feature
NotFound
404 - Bad endpoint or invalid model ID
RequestTooLarge
413 - Request body too large (too many tokens, huge images, etc.)
RateLimited
429 - Rate limited (retryable - check retry-after header)
InternalError
500 - Anthropic server issue (retryable)
Overloaded
529 - API overloaded (retryable)
Network(Error)
Network-level failure (DNS, TLS, connection refused, etc.)
JsonParse(Error)
Failed to parse the API response JSON
StreamError
SSE stream delivered an error event or broke mid-stream
Unknown
Catch-all for unexpected HTTP status codes
Implementations§
Source§impl ClaudeApiError
impl ClaudeApiError
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Returns true if the error is safe to retry with backoff.
Source§impl ClaudeApiError
impl ClaudeApiError
Sourcepub fn from_response(status: u16, body: &str) -> Self
pub fn from_response(status: u16, body: &str) -> Self
Parse an API error from the HTTP status code and response body text.
Tries to deserialize the structured error JSON first; falls back to using the raw body text if parsing fails.
Trait Implementations§
Source§impl Debug for ClaudeApiError
impl Debug for ClaudeApiError
Source§impl Display for ClaudeApiError
impl Display for ClaudeApiError
Source§impl Error for ClaudeApiError
impl Error for ClaudeApiError
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
use the Display impl or to_string()
Source§impl From<Error> for ClaudeApiError
impl From<Error> for ClaudeApiError
Auto Trait Implementations§
impl Freeze for ClaudeApiError
impl !RefUnwindSafe for ClaudeApiError
impl Send for ClaudeApiError
impl Sync for ClaudeApiError
impl Unpin for ClaudeApiError
impl UnsafeUnpin for ClaudeApiError
impl !UnwindSafe for ClaudeApiError
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
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.