mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
feat(core): improve run_mobile_plugin error handling (#6655)
This commit is contained in:
committed by
GitHub
parent
be941b9719
commit
f0570d9fee
5
.changes/improve-mobile-plugin-error-handling.md
Normal file
5
.changes/improve-mobile-plugin-error-handling.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Improve the `run_mobile_plugin` function error handling.
|
||||
@@ -38,7 +38,10 @@ pub enum PluginInvokeError {
|
||||
Jni(#[from] jni::errors::Error),
|
||||
/// Error returned from direct mobile plugin invoke.
|
||||
#[error(transparent)]
|
||||
InvokeRejected(#[from] crate::plugin::mobile::ErrorResponse),
|
||||
InvokeRejected(#[from] ErrorResponse),
|
||||
/// Failed to deserialize response.
|
||||
#[error("failed to deserialize response: {0}")]
|
||||
CannotDeserializeResponse(serde_json::Error),
|
||||
}
|
||||
|
||||
/// Glue between Rust and the Kotlin code that sends the plugin response back.
|
||||
@@ -289,10 +292,16 @@ impl<R: Runtime> PluginHandle<R> {
|
||||
crate::ios::PluginMessageCallback(plugin_method_response_handler),
|
||||
);
|
||||
}
|
||||
rx.recv()
|
||||
.unwrap()
|
||||
.map(|r| serde_json::from_value(r).unwrap())
|
||||
.map_err(|e| serde_json::from_value::<ErrorResponse>(e).unwrap().into())
|
||||
|
||||
let response = rx.recv().unwrap();
|
||||
match response {
|
||||
Ok(r) => serde_json::from_value(r).map_err(PluginInvokeError::CannotDeserializeResponse),
|
||||
Err(r) => Err(
|
||||
serde_json::from_value::<ErrorResponse>(r)
|
||||
.map(Into::into)
|
||||
.map_err(PluginInvokeError::CannotDeserializeResponse)?,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// Executes the given Android method.
|
||||
@@ -370,8 +379,13 @@ impl<R: Runtime> PluginHandle<R> {
|
||||
});
|
||||
|
||||
let response = rx.recv().unwrap()?;
|
||||
response
|
||||
.map(|r| serde_json::from_value(r).unwrap())
|
||||
.map_err(|e| serde_json::from_value::<ErrorResponse>(e).unwrap().into())
|
||||
match response {
|
||||
Ok(r) => serde_json::from_value(r).map_err(PluginInvokeError::CannotDeserializeResponse),
|
||||
Err(r) => Err(
|
||||
serde_json::from_value::<ErrorResponse>(r)
|
||||
.map(Into::into)
|
||||
.map_err(PluginInvokeError::CannotDeserializeResponse)?,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user