use axum::{Json, http::StatusCode, response::{IntoResponse, Response}}; use serde_json::json; use thiserror::Error; #[derive(Debug, Error)] pub enum ResolveError { #[error("invalid handle or DID")] InvalidIdentifier, #[error("could not resolve identity")] Upstream, #[error("No handles found associated with DID")] NoHandleFound, #[error("No PDS server found associated with DID")] NoPdsFound, #[error("Failed to convert an internal type")] TypeConversionError, #[error("Failed to fetch record")] FailedToFetchRecord, } impl IntoResponse for ResolveError { fn into_response(self) -> Response { let status = match &self { Self::InvalidIdentifier => StatusCode::BAD_REQUEST, Self::Upstream => StatusCode::BAD_GATEWAY, Self::NoHandleFound => StatusCode::NOT_FOUND, Self::NoPdsFound => StatusCode::NOT_FOUND, Self::FailedToFetchRecord => StatusCode::NOT_FOUND, _ => StatusCode::INTERNAL_SERVER_ERROR, }; (status, Json(json!({ "error": self.to_string() }))) .into_response() } }