@@ -2,16 +2,63 @@ use serde::{ser::Serializer, Serialize};
22
33pub type Result < T > = std:: result:: Result < T , Error > ;
44
5+ /// Replica of the tauri::plugin::mobile::ErrorResponse for desktop platforms.
6+ #[ cfg( desktop) ]
7+ #[ derive( Debug , thiserror:: Error , Clone , serde:: Deserialize ) ]
8+ pub struct ErrorResponse < T = ( ) > {
9+ /// Error code.
10+ pub code : Option < String > ,
11+ /// Error message.
12+ pub message : Option < String > ,
13+ /// Optional error data.
14+ #[ serde( flatten) ]
15+ pub data : T ,
16+ }
17+
18+ #[ cfg( desktop) ]
19+ impl < T > std:: fmt:: Display for ErrorResponse < T > {
20+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
21+ if let Some ( code) = & self . code {
22+ write ! ( f, "[{code}]" ) ?;
23+ if self . message . is_some ( ) {
24+ write ! ( f, " - " ) ?;
25+ }
26+ }
27+ if let Some ( message) = & self . message {
28+ write ! ( f, "{message}" ) ?;
29+ }
30+ Ok ( ( ) )
31+ }
32+ }
33+
34+ /// Replica of the tauri::plugin::mobile::PluginInvokeError for desktop platforms.
35+ #[ cfg( desktop) ]
36+ #[ derive( Debug , thiserror:: Error ) ]
37+ pub enum PluginInvokeError {
38+ /// Error returned from direct desktop plugin.
39+ #[ error( transparent) ]
40+ InvokeRejected ( #[ from] ErrorResponse ) ,
41+ /// Failed to deserialize response.
42+ #[ error( "failed to deserialize response: {0}" ) ]
43+ CannotDeserializeResponse ( serde_json:: Error ) ,
44+ /// Failed to serialize request payload.
45+ #[ error( "failed to serialize payload: {0}" ) ]
46+ CannotSerializePayload ( serde_json:: Error ) ,
47+ }
48+
549#[ derive( Debug , thiserror:: Error ) ]
650pub enum Error {
751 #[ error( transparent) ]
852 Io ( #[ from] std:: io:: Error ) ,
953 #[ cfg( mobile) ]
1054 #[ error( transparent) ]
1155 PluginInvoke ( #[ from] tauri:: plugin:: mobile:: PluginInvokeError ) ,
12- #[ cfg( all( target_os = "macos" , feature = "unstable" ) ) ]
56+ #[ cfg( desktop) ]
57+ #[ error( transparent) ]
58+ PluginInvoke ( #[ from] crate :: error:: PluginInvokeError ) ,
59+ #[ cfg( target_os = "windows" ) ]
1360 #[ error( transparent) ]
14- PluginInvoke ( #[ from] serde_json :: Error ) ,
61+ WindowsApi ( #[ from] windows_result :: Error ) ,
1562}
1663
1764impl Serialize for Error {
0 commit comments