From adac93b9f10284e10bc58b436bb91284ed2cd132 Mon Sep 17 00:00:00 2001 From: Noah Klayman Date: Sat, 27 Feb 2021 22:03:28 -0800 Subject: [PATCH] fix(core): pass unkown api error to webview (#1304) --- tauri/src/app/utils.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tauri/src/app/utils.rs b/tauri/src/app/utils.rs index d95c61b30..49679e9ec 100644 --- a/tauri/src/app/utils.rs +++ b/tauri/src/app/utils.rs @@ -339,9 +339,20 @@ async fn on_message( Err(e) => Err(e), }; if let Err(crate::Error::UnknownApi(_)) = response { - response = crate::plugin::extend_api(A::plugin_store(), &webview_manager, &message.inner) - .await - .map(|value| value.into()); + match crate::plugin::extend_api(A::plugin_store(), &webview_manager, &message.inner).await { + Ok(value) => { + // If value is None, that means that no plugin matched the command + // and the UnknownApi error should be sent to the webview + // Otherwise, send the result of plugin handler + if value.is_some() { + response = Ok(value.into()); + } + } + Err(e) => { + // A plugin handler was found but it failed + response = Err(e); + } + } } response };