@@ -30,8 +30,8 @@ pub type AuthToken = String;
30
30
) ]
31
31
#[ serde( tag = "type" , rename_all = "SCREAMING_SNAKE_CASE" ) ]
32
32
pub enum IAWError {
33
- #[ error( "API error: {0 }" ) ]
34
- ApiError ( String ) ,
33
+ #[ error( "API error: {message }" ) ]
34
+ ApiError { message : String } ,
35
35
#[ error( "Serialization error: {message}" ) ]
36
36
SerializationError { message : String } ,
37
37
#[ error( "Network error: {error}" ) ]
@@ -197,14 +197,16 @@ impl IAWClient {
197
197
. await ?;
198
198
199
199
if !response. status ( ) . is_success ( ) {
200
- return Err ( IAWError :: ApiError ( format ! (
201
- "Failed to sign message - {} {}" ,
202
- response. status( ) ,
203
- response
204
- . status( )
205
- . canonical_reason( )
206
- . unwrap_or( "Unknown error" )
207
- ) ) ) ;
200
+ return Err ( IAWError :: ApiError {
201
+ message : format ! (
202
+ "Failed to sign message - {} {}" ,
203
+ response. status( ) ,
204
+ response
205
+ . status( )
206
+ . canonical_reason( )
207
+ . unwrap_or( "Unknown error" )
208
+ ) ,
209
+ } ) ;
208
210
}
209
211
210
212
// Parse the response
@@ -214,7 +216,9 @@ impl IAWClient {
214
216
let signature = signed_response
215
217
. get ( "signature" )
216
218
. and_then ( |s| s. as_str ( ) )
217
- . ok_or_else ( || IAWError :: ApiError ( "No signature in response" . to_string ( ) ) ) ?;
219
+ . ok_or_else ( || IAWError :: ApiError {
220
+ message : "No signature in response" . to_string ( ) ,
221
+ } ) ?;
218
222
219
223
Ok ( SignMessageData {
220
224
signature : signature. to_string ( ) ,
@@ -262,14 +266,16 @@ impl IAWClient {
262
266
. await ?;
263
267
264
268
if !response. status ( ) . is_success ( ) {
265
- return Err ( IAWError :: ApiError ( format ! (
266
- "Failed to sign typed data - {} {}" ,
267
- response. status( ) ,
268
- response
269
- . status( )
270
- . canonical_reason( )
271
- . unwrap_or( "Unknown error" )
272
- ) ) ) ;
269
+ return Err ( IAWError :: ApiError {
270
+ message : format ! (
271
+ "Failed to sign typed data - {} {}" ,
272
+ response. status( ) ,
273
+ response
274
+ . status( )
275
+ . canonical_reason( )
276
+ . unwrap_or( "Unknown error" )
277
+ ) ,
278
+ } ) ;
273
279
}
274
280
275
281
// Parse the response
@@ -279,7 +285,9 @@ impl IAWClient {
279
285
let signature = signed_response
280
286
. get ( "signature" )
281
287
. and_then ( |s| s. as_str ( ) )
282
- . ok_or_else ( || IAWError :: ApiError ( "No signature in response" . to_string ( ) ) ) ?;
288
+ . ok_or_else ( || IAWError :: ApiError {
289
+ message : "No signature in response" . to_string ( ) ,
290
+ } ) ?;
283
291
284
292
Ok ( SignTypedDataData {
285
293
signature : signature. to_string ( ) ,
@@ -328,14 +336,16 @@ impl IAWClient {
328
336
. await ?;
329
337
330
338
if !response. status ( ) . is_success ( ) {
331
- return Err ( IAWError :: ApiError ( format ! (
332
- "Failed to sign transaction - {} {}" ,
333
- response. status( ) ,
334
- response
335
- . status( )
336
- . canonical_reason( )
337
- . unwrap_or( "Unknown error" )
338
- ) ) ) ;
339
+ return Err ( IAWError :: ApiError {
340
+ message : format ! (
341
+ "Failed to sign transaction - {} {}" ,
342
+ response. status( ) ,
343
+ response
344
+ . status( )
345
+ . canonical_reason( )
346
+ . unwrap_or( "Unknown error" )
347
+ ) ,
348
+ } ) ;
339
349
}
340
350
341
351
// Parse the response
@@ -345,7 +355,9 @@ impl IAWClient {
345
355
let signature = signed_response
346
356
. get ( "signature" )
347
357
. and_then ( |s| s. as_str ( ) )
348
- . ok_or_else ( || IAWError :: ApiError ( "No signature in response" . to_string ( ) ) ) ?;
358
+ . ok_or_else ( || IAWError :: ApiError {
359
+ message : "No signature in response" . to_string ( ) ,
360
+ } ) ?;
349
361
350
362
Ok ( SignTransactionData {
351
363
signature : signature. to_string ( ) ,
@@ -397,14 +409,16 @@ impl IAWClient {
397
409
. await ?;
398
410
399
411
if !response. status ( ) . is_success ( ) {
400
- return Err ( IAWError :: ApiError ( format ! (
401
- "Failed to sign authorization - {} {}" ,
402
- response. status( ) ,
403
- response
404
- . status( )
405
- . canonical_reason( )
406
- . unwrap_or( "Unknown error" )
407
- ) ) ) ;
412
+ return Err ( IAWError :: ApiError {
413
+ message : format ! (
414
+ "Failed to sign authorization - {} {}" ,
415
+ response. status( ) ,
416
+ response
417
+ . status( )
418
+ . canonical_reason( )
419
+ . unwrap_or( "Unknown error" )
420
+ ) ,
421
+ } ) ;
408
422
}
409
423
410
424
// Parse the response
@@ -414,8 +428,8 @@ impl IAWClient {
414
428
let signed_authorization: SignedAuthorization = serde_json:: from_value (
415
429
signed_response
416
430
. get ( "signedAuthorization" )
417
- . ok_or_else ( || {
418
- IAWError :: ApiError ( "No signedAuthorization in response" . to_string ( ) )
431
+ . ok_or_else ( || IAWError :: ApiError {
432
+ message : "No signedAuthorization in response" . to_string ( ) ,
419
433
} ) ?
420
434
. clone ( ) ,
421
435
) ?;
@@ -483,14 +497,16 @@ impl IAWClient {
483
497
. await ?;
484
498
485
499
if !response. status ( ) . is_success ( ) {
486
- return Err ( IAWError :: ApiError ( format ! (
487
- "Failed to sign userop - {} {}" ,
488
- response. status( ) ,
489
- response
490
- . status( )
491
- . canonical_reason( )
492
- . unwrap_or( "Unknown error" )
493
- ) ) ) ;
500
+ return Err ( IAWError :: ApiError {
501
+ message : format ! (
502
+ "Failed to sign userop - {} {}" ,
503
+ response. status( ) ,
504
+ response
505
+ . status( )
506
+ . canonical_reason( )
507
+ . unwrap_or( "Unknown error" )
508
+ ) ,
509
+ } ) ;
494
510
}
495
511
496
512
// Parse the response
@@ -500,7 +516,9 @@ impl IAWClient {
500
516
let signature = signed_response
501
517
. get ( "signature" )
502
518
. and_then ( |s| s. as_str ( ) )
503
- . ok_or_else ( || IAWError :: ApiError ( "No signature in response" . to_string ( ) ) ) ?;
519
+ . ok_or_else ( || IAWError :: ApiError {
520
+ message : "No signature in response" . to_string ( ) ,
521
+ } ) ?;
504
522
505
523
Ok ( SignUserOpData {
506
524
signature : signature. to_string ( ) ,
0 commit comments