Skip to content

Commit c2db060

Browse files
committed
use WithRejection also with Multipart
1 parent 4ec3b6d commit c2db060

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/error.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use amplify::s;
22
use axum::{
3-
extract::rejection::JsonRejection,
43
http::StatusCode,
54
response::{IntoResponse, Response},
65
Json,
@@ -192,6 +191,9 @@ pub enum APIError {
192191
#[error("The provided recipient ID is for a different network than the wallet's one")]
193192
InvalidRecipientNetwork,
194193

194+
#[error("Invalid request: {0}")]
195+
InvalidRequest(String),
196+
195197
#[error("Invalid swap: {0}")]
196198
InvalidSwap(String),
197199

@@ -213,9 +215,6 @@ pub enum APIError {
213215
#[error("IO error: {0}")]
214216
IO(#[from] std::io::Error),
215217

216-
#[error(transparent)]
217-
JsonExtractorRejection(#[from] JsonRejection),
218-
219218
#[error("Node is locked (hint: call unlock)")]
220219
LockedNode,
221220

@@ -314,6 +313,18 @@ impl APIError {
314313
}
315314
}
316315

316+
impl From<axum::extract::rejection::JsonRejection> for APIError {
317+
fn from(err: axum::extract::rejection::JsonRejection) -> Self {
318+
APIError::InvalidRequest(err.to_string())
319+
}
320+
}
321+
322+
impl From<axum::extract::multipart::MultipartRejection> for APIError {
323+
fn from(err: axum::extract::multipart::MultipartRejection) -> Self {
324+
APIError::InvalidRequest(err.to_string())
325+
}
326+
}
327+
317328
impl From<RgbLibError> for APIError {
318329
fn from(error: RgbLibError) -> Self {
319330
match error {
@@ -395,11 +406,6 @@ impl From<RgbLibError> for APIError {
395406
impl IntoResponse for APIError {
396407
fn into_response(self) -> Response {
397408
let (status, error, name) = match self {
398-
APIError::JsonExtractorRejection(ref json_rejection) => (
399-
json_rejection.status(),
400-
json_rejection.body_text(),
401-
self.name(),
402-
),
403409
APIError::FailedClosingChannel(_)
404410
| APIError::FailedInvoiceCreation(_)
405411
| APIError::FailedIssuingAsset(_)
@@ -444,6 +450,7 @@ impl IntoResponse for APIError {
444450
| APIError::InvalidRecipientData(_)
445451
| APIError::InvalidRecipientID
446452
| APIError::InvalidRecipientNetwork
453+
| APIError::InvalidRequest(_)
447454
| APIError::InvalidSwap(_)
448455
| APIError::InvalidSwapString(_, _)
449456
| APIError::InvalidTicker(_)

src/routes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3225,7 +3225,7 @@ pub(crate) async fn open_channel(
32253225

32263226
pub(crate) async fn post_asset_media(
32273227
State(state): State<Arc<AppState>>,
3228-
mut multipart: Multipart,
3228+
WithRejection(mut multipart, _): WithRejection<Multipart, APIError>,
32293229
) -> Result<Json<PostAssetMediaResponse>, APIError> {
32303230
no_cancel(async move {
32313231
let guard = state.check_unlocked().await?;

0 commit comments

Comments
 (0)