···
1
-
use jacquard_common::error::{AuthError, ClientError};
1
+
use jacquard_common::error::{AuthError, ClientError, ClientErrorKind};
use jacquard_common::types::did::Did;
use jacquard_common::types::nsid::Nsid;
use jacquard_common::types::string::{RecordKey, Rkey};
···
/// Error type for Agent convenience methods
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
···
xrpc: Option<Data<'static>>,
28
+
impl std::fmt::Display for AgentError {
29
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30
+
write!(f, "{}", self.kind)?;
32
+
// Add context if available
33
+
if let Some(context) = &self.context {
34
+
write!(f, ": {}", context)?;
37
+
// Add URL if available
38
+
if let Some(url) = &self.url {
39
+
write!(f, " (url: {})", url)?;
42
+
// Add details if available
43
+
if let Some(details) = &self.details {
44
+
write!(f, " [{}]", details)?;
/// Error categories for Agent operations
#[derive(Debug, thiserror::Error, miette::Diagnostic)]
pub enum AgentErrorKind {
/// Transport/network layer failure
33
-
#[error("client error")]
34
-
#[diagnostic(code(jacquard::agent::client))]
55
+
#[error("client error (see context for details)")]
57
+
code(jacquard::agent::client),
58
+
help("check source error and context for specific failure details")
/// No session available for operations requiring authentication
···
impl From<ClientError> for AgentError {
fn from(e: ClientError) -> Self {
229
-
Self::new(AgentErrorKind::Client, Some(Box::new(e)))
254
+
use smol_str::ToSmolStr;
256
+
let context_msg: SmolStr;
257
+
let help_msg: SmolStr;
258
+
let url = e.url().map(|s| s.to_smolstr());
259
+
let details = e.details().map(|s| s.to_smolstr());
261
+
// Build context and help based on the error kind
263
+
ClientErrorKind::Transport => {
264
+
help_msg = "check network connectivity and server availability".to_smolstr();
265
+
context_msg = "network/transport error during request".to_smolstr();
267
+
ClientErrorKind::InvalidRequest(msg) => {
268
+
help_msg = "verify request parameters are valid".to_smolstr();
269
+
context_msg = smol_str::format_smolstr!("invalid request: {}", msg);
271
+
ClientErrorKind::Encode(msg) => {
272
+
help_msg = "check request body format".to_smolstr();
273
+
context_msg = smol_str::format_smolstr!("failed to encode request: {}", msg);
275
+
ClientErrorKind::Decode(msg) => {
276
+
help_msg = "server returned unexpected response format".to_smolstr();
277
+
context_msg = smol_str::format_smolstr!("failed to decode response: {}", msg);
279
+
ClientErrorKind::Http { status } => {
280
+
help_msg = match status.as_u16() {
281
+
400..=499 => "check request parameters and authentication",
282
+
500..=599 => "server error - try again later or check server logs",
283
+
_ => "unexpected HTTP status code",
286
+
context_msg = smol_str::format_smolstr!("HTTP error {}", status);
288
+
ClientErrorKind::Auth(auth_err) => {
289
+
help_msg = "verify authentication credentials and session".to_smolstr();
290
+
context_msg = smol_str::format_smolstr!("authentication error: {}", auth_err);
292
+
ClientErrorKind::IdentityResolution => {
293
+
help_msg = "check handle/DID is valid and resolvable".to_smolstr();
294
+
context_msg = "identity resolution failed".to_smolstr();
296
+
ClientErrorKind::Storage => {
297
+
help_msg = "verify storage backend is accessible".to_smolstr();
298
+
context_msg = "storage operation failed".to_smolstr();
302
+
let mut error = Self::new(AgentErrorKind::Client, Some(Box::new(e)));
303
+
error = error.with_context(context_msg);
304
+
error = error.with_help(help_msg);
306
+
if let Some(url) = url {
307
+
error = error.with_url(url);
309
+
if let Some(details) = details {
310
+
error = error.with_details(details);