11use amplify:: s;
22use 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+
317328impl From < RgbLibError > for APIError {
318329 fn from ( error : RgbLibError ) -> Self {
319330 match error {
@@ -395,11 +406,6 @@ impl From<RgbLibError> for APIError {
395406impl 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 ( _)
0 commit comments