MCPcopy Create free account
hub / github.com/Louisym/MiniCC / fmt

Method fmt

rust/crates/api/src/error.rs:52–107  ·  view source on GitHub ↗
(&self, f: &mut Formatter<'_>)

Source from the content-addressed store, hash-verified

50
51impl Display for ApiError {
52 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
53 match self {
54 Self::MissingApiKey => {
55 write!(
56 f,
57 "ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY is not set; export one before calling the Anthropic API"
58 )
59 }
60 Self::ExpiredOAuthToken => {
61 write!(
62 f,
63 "saved OAuth token is expired and no refresh token is available"
64 )
65 }
66 Self::Auth(message) => write!(f, "auth error: {message}"),
67 Self::InvalidApiKeyEnv(error) => {
68 write!(
69 f,
70 "failed to read ANTHROPIC_AUTH_TOKEN / ANTHROPIC_API_KEY: {error}"
71 )
72 }
73 Self::Http(error) => write!(f, "http error: {error}"),
74 Self::Io(error) => write!(f, "io error: {error}"),
75 Self::Json(error) => write!(f, "json error: {error}"),
76 Self::Api {
77 status,
78 error_type,
79 message,
80 body,
81 ..
82 } => match (error_type, message) {
83 (Some(error_type), Some(message)) => {
84 write!(
85 f,
86 "anthropic api returned {status} ({error_type}): {message}"
87 )
88 }
89 _ => write!(f, "anthropic api returned {status}: {body}"),
90 },
91 Self::RetriesExhausted {
92 attempts,
93 last_error,
94 } => write!(
95 f,
96 "anthropic api failed after {attempts} attempts: {last_error}"
97 ),
98 Self::InvalidSseFrame(message) => write!(f, "invalid sse frame: {message}"),
99 Self::BackoffOverflow {
100 attempt,
101 base_delay,
102 } => write!(
103 f,
104 "retry backoff overflowed on attempt {attempt} with base delay {base_delay:?}"
105 ),
106 }
107 }
108}
109

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected