1
1
use crate :: api:: error:: LdkServerError ;
2
- use crate :: api:: error:: LdkServerErrorCode :: InvalidRequestError ;
2
+ use crate :: api:: error:: LdkServerErrorCode :: {
3
+ AuthError , InternalServerError , InvalidRequestError , LightningError ,
4
+ } ;
3
5
use bytes:: Bytes ;
4
6
use hex:: prelude:: * ;
7
+ use hyper:: StatusCode ;
5
8
use ldk_node:: bitcoin:: hashes:: sha256;
6
9
use ldk_node:: bitcoin:: secp256k1:: PublicKey ;
7
10
use ldk_node:: config:: { ChannelConfig , MaxDustHTLCExposure } ;
@@ -11,6 +14,7 @@ use ldk_node::payment::{
11
14
ConfirmationStatus , PaymentDetails , PaymentDirection , PaymentKind , PaymentStatus ,
12
15
} ;
13
16
use ldk_node:: { ChannelDetails , LightningBalance , PendingSweepBalance , UserChannelId } ;
17
+ use ldk_server_protos:: error:: { ErrorCode , ErrorResponse } ;
14
18
use ldk_server_protos:: types:: confirmation_status:: Status :: { Confirmed , Unconfirmed } ;
15
19
use ldk_server_protos:: types:: lightning_balance:: BalanceType :: {
16
20
ClaimableAwaitingConfirmations , ClaimableOnChannelClose , ContentiousClaimable ,
@@ -409,3 +413,23 @@ pub(crate) fn proto_to_bolt11_description(
409
413
} ,
410
414
} )
411
415
}
416
+
417
+ pub ( crate ) fn to_error_response ( ldk_error : LdkServerError ) -> ( ErrorResponse , StatusCode ) {
418
+ let error_code = match ldk_error. error_code {
419
+ InvalidRequestError => ErrorCode :: InvalidRequestError ,
420
+ AuthError => ErrorCode :: AuthError ,
421
+ LightningError => ErrorCode :: LightningError ,
422
+ InternalServerError => ErrorCode :: InternalServerError ,
423
+ } as i32 ;
424
+
425
+ let status = match ldk_error. error_code {
426
+ InvalidRequestError => StatusCode :: BAD_REQUEST ,
427
+ AuthError => StatusCode :: UNAUTHORIZED ,
428
+ LightningError => StatusCode :: INTERNAL_SERVER_ERROR ,
429
+ InternalServerError => StatusCode :: INTERNAL_SERVER_ERROR ,
430
+ } ;
431
+
432
+ let error_response = ErrorResponse { message : ldk_error. message , error_code } ;
433
+
434
+ ( error_response, status)
435
+ }
0 commit comments