Add details to Mural API errors (#4886)

This commit is contained in:
aecsocket
2025-12-11 12:49:59 +00:00
committed by GitHub
parent 3dd2de5f18
commit ddcc14d99f
8 changed files with 16 additions and 1 deletions

View File

@@ -85,6 +85,7 @@ impl actix_web::ResponseError for AuthenticationError {
HttpResponse::build(self.status_code()).json(ApiError {
error: self.error_name(),
description: self.to_string(),
details: None,
})
}
}

View File

@@ -105,6 +105,7 @@ impl actix_web::ResponseError for OAuthError {
HttpResponse::build(self.status_code()).json(ApiError {
error: &self.error_type.error_name(),
description: self.error_type.to_string(),
details: None,
})
}
}

View File

@@ -5,4 +5,6 @@ use serde::{Deserialize, Serialize};
pub struct ApiError<'a> {
pub error: &'a str,
pub description: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub details: Option<serde_json::Value>,
}

View File

@@ -177,7 +177,7 @@ impl PayoutsQueue {
)
.await
.map_err(|err| match err {
MuralError::Api(err) => ApiError::Request(err.into()),
MuralError::Api(err) => ApiError::Mural(Box::new(err)),
err => ApiError::Internal(
eyre!(err).wrap_err("failed to create payout request"),
),

View File

@@ -161,6 +161,8 @@ pub enum ApiError {
RateLimitError(u128, u32),
#[error("Error while interacting with payment processor: {0}")]
Stripe(#[from] stripe::StripeError),
#[error(transparent)]
Mural(#[from] Box<muralpay::ApiError>),
}
impl ApiError {
@@ -201,6 +203,7 @@ impl ApiError {
Self::Stripe(..) => "stripe_error",
Self::TaxProcessor(..) => "tax_processor_error",
Self::Slack(..) => "slack_error",
Self::Mural(..) => "mural_error",
},
description: match self {
Self::Internal(e) => format!("{e:#?}"),
@@ -208,6 +211,10 @@ impl ApiError {
Self::Auth(e) => format!("{e:#?}"),
_ => self.to_string(),
},
details: match self {
Self::Mural(err) => serde_json::to_value(err.clone()).ok(),
_ => None,
},
}
}
}
@@ -249,6 +256,7 @@ impl actix_web::ResponseError for ApiError {
Self::Stripe(..) => StatusCode::FAILED_DEPENDENCY,
Self::TaxProcessor(..) => StatusCode::INTERNAL_SERVER_ERROR,
Self::Slack(..) => StatusCode::INTERNAL_SERVER_ERROR,
Self::Mural(..) => StatusCode::BAD_REQUEST,
}
}

View File

@@ -5,6 +5,7 @@ pub async fn not_found() -> impl Responder {
let data = ApiError {
error: "not_found",
description: "the requested route does not exist".to_string(),
details: None,
};
HttpResponse::NotFound().json(data)

View File

@@ -151,6 +151,7 @@ impl actix_web::ResponseError for CreateError {
CreateError::LimitReached => "limit_reached",
},
description: self.to_string(),
details: None,
})
}
}

View File

@@ -53,6 +53,7 @@ impl actix_web::ResponseError for SearchError {
SearchError::FormatError(..) => "invalid_input",
},
description: self.to_string(),
details: None,
})
}
}