@@ -38,7 +38,10 @@ pub enum PluginInvokeError {
38
38
Jni ( #[ from] jni:: errors:: Error ) ,
39
39
/// Error returned from direct mobile plugin invoke.
40
40
#[ error( transparent) ]
41
- InvokeRejected ( #[ from] crate :: plugin:: mobile:: ErrorResponse ) ,
41
+ InvokeRejected ( #[ from] ErrorResponse ) ,
42
+ /// Failed to deserialize response.
43
+ #[ error( "failed to deserialize response: {0}" ) ]
44
+ CannotDeserializeResponse ( serde_json:: Error ) ,
42
45
}
43
46
44
47
/// Glue between Rust and the Kotlin code that sends the plugin response back.
@@ -289,10 +292,16 @@ impl<R: Runtime> PluginHandle<R> {
289
292
crate :: ios:: PluginMessageCallback ( plugin_method_response_handler) ,
290
293
) ;
291
294
}
292
- rx. recv ( )
293
- . unwrap ( )
294
- . map ( |r| serde_json:: from_value ( r) . unwrap ( ) )
295
- . map_err ( |e| serde_json:: from_value :: < ErrorResponse > ( e) . unwrap ( ) . into ( ) )
295
+
296
+ let response = rx. recv ( ) . unwrap ( ) ;
297
+ match response {
298
+ Ok ( r) => serde_json:: from_value ( r) . map_err ( PluginInvokeError :: CannotDeserializeResponse ) ,
299
+ Err ( r) => Err (
300
+ serde_json:: from_value :: < ErrorResponse > ( r)
301
+ . map ( Into :: into)
302
+ . map_err ( PluginInvokeError :: CannotDeserializeResponse ) ?,
303
+ ) ,
304
+ }
296
305
}
297
306
298
307
// Executes the given Android method.
@@ -370,8 +379,13 @@ impl<R: Runtime> PluginHandle<R> {
370
379
} ) ;
371
380
372
381
let response = rx. recv ( ) . unwrap ( ) ?;
373
- response
374
- . map ( |r| serde_json:: from_value ( r) . unwrap ( ) )
375
- . map_err ( |e| serde_json:: from_value :: < ErrorResponse > ( e) . unwrap ( ) . into ( ) )
382
+ match response {
383
+ Ok ( r) => serde_json:: from_value ( r) . map_err ( PluginInvokeError :: CannotDeserializeResponse ) ,
384
+ Err ( r) => Err (
385
+ serde_json:: from_value :: < ErrorResponse > ( r)
386
+ . map ( Into :: into)
387
+ . map_err ( PluginInvokeError :: CannotDeserializeResponse ) ?,
388
+ ) ,
389
+ }
376
390
}
377
391
}
0 commit comments