|
@@ -3,7 +3,7 @@ use axum::extract::ws::WebSocketUpgrade;
|
|
|
use axum::extract::{Json, Path, State};
|
|
|
use axum::http::StatusCode;
|
|
|
use axum::response::{IntoResponse, Response};
|
|
|
-use cdk::error::ErrorResponse;
|
|
|
+use cdk::error::{ErrorCode, ErrorResponse};
|
|
|
#[cfg(feature = "auth")]
|
|
|
use cdk::nuts::nut21::{Method, ProtectedEndpoint, RoutePath};
|
|
|
use cdk::nuts::{
|
|
@@ -544,9 +544,38 @@ pub(crate) fn into_response<T>(error: T) -> Response
|
|
|
where
|
|
|
T: Into<ErrorResponse>,
|
|
|
{
|
|
|
- (
|
|
|
- StatusCode::INTERNAL_SERVER_ERROR,
|
|
|
- Json::<ErrorResponse>(error.into()),
|
|
|
- )
|
|
|
- .into_response()
|
|
|
+ let err_response: ErrorResponse = error.into();
|
|
|
+ let status_code = match err_response.code {
|
|
|
+ // Client errors (400 Bad Request)
|
|
|
+ ErrorCode::TokenAlreadySpent
|
|
|
+ | ErrorCode::TokenPending
|
|
|
+ | ErrorCode::QuoteNotPaid
|
|
|
+ | ErrorCode::QuoteExpired
|
|
|
+ | ErrorCode::QuotePending
|
|
|
+ | ErrorCode::KeysetNotFound
|
|
|
+ | ErrorCode::KeysetInactive
|
|
|
+ | ErrorCode::BlindedMessageAlreadySigned
|
|
|
+ | ErrorCode::UnsupportedUnit
|
|
|
+ | ErrorCode::TokensAlreadyIssued
|
|
|
+ | ErrorCode::MintingDisabled
|
|
|
+ | ErrorCode::InvoiceAlreadyPaid
|
|
|
+ | ErrorCode::TokenNotVerified
|
|
|
+ | ErrorCode::TransactionUnbalanced
|
|
|
+ | ErrorCode::AmountOutofLimitRange
|
|
|
+ | ErrorCode::WitnessMissingOrInvalid
|
|
|
+ | ErrorCode::DuplicateInputs
|
|
|
+ | ErrorCode::DuplicateOutputs
|
|
|
+ | ErrorCode::MultipleUnits
|
|
|
+ | ErrorCode::UnitMismatch
|
|
|
+ | ErrorCode::ClearAuthRequired
|
|
|
+ | ErrorCode::BlindAuthRequired => StatusCode::BAD_REQUEST,
|
|
|
+
|
|
|
+ // Auth failures (401 Unauthorized)
|
|
|
+ ErrorCode::ClearAuthFailed | ErrorCode::BlindAuthFailed => StatusCode::UNAUTHORIZED,
|
|
|
+
|
|
|
+ // Lightning/payment errors and unknown errors (500 Internal Server Error)
|
|
|
+ ErrorCode::LightningError | ErrorCode::Unknown(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
|
|
+ };
|
|
|
+
|
|
|
+ (status_code, Json(err_response)).into_response()
|
|
|
}
|