mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-20 06:05:09 +01:00
Merge pull request #858 from thesimplekid/mint_error_code
fix: mint error codes
This commit is contained in:
@@ -3,7 +3,7 @@ use axum::extract::ws::WebSocketUpgrade;
|
|||||||
use axum::extract::{Json, Path, State};
|
use axum::extract::{Json, Path, State};
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
use axum::response::{IntoResponse, Response};
|
use axum::response::{IntoResponse, Response};
|
||||||
use cdk::error::ErrorResponse;
|
use cdk::error::{ErrorCode, ErrorResponse};
|
||||||
#[cfg(feature = "auth")]
|
#[cfg(feature = "auth")]
|
||||||
use cdk::nuts::nut21::{Method, ProtectedEndpoint, RoutePath};
|
use cdk::nuts::nut21::{Method, ProtectedEndpoint, RoutePath};
|
||||||
use cdk::nuts::{
|
use cdk::nuts::{
|
||||||
@@ -544,9 +544,38 @@ pub(crate) fn into_response<T>(error: T) -> Response
|
|||||||
where
|
where
|
||||||
T: Into<ErrorResponse>,
|
T: Into<ErrorResponse>,
|
||||||
{
|
{
|
||||||
(
|
let err_response: ErrorResponse = error.into();
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
let status_code = match err_response.code {
|
||||||
Json::<ErrorResponse>(error.into()),
|
// Client errors (400 Bad Request)
|
||||||
)
|
ErrorCode::TokenAlreadySpent
|
||||||
.into_response()
|
| 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()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user