Skip to main content

tauri_plugin_geolocation/
error.rs

1// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2// SPDX-License-Identifier: Apache-2.0
3// SPDX-License-Identifier: MIT
4
5use serde::{Serialize, ser::Serializer};
6
7/// Alias for the result type returned by the geolocation APIs.
8pub type Result<T> = std::result::Result<T, Error>;
9
10// TODO: Improve Error handling (different typed errors instead of one (stringified) PluginInvokeError for all mobile errors)
11
12/// Errors that can occur while interacting with the geolocation APIs.
13#[derive(Debug, thiserror::Error)]
14#[cfg_attr(feature = "specta", derive(specta::Type))]
15pub enum Error {
16    /// Forwards an error returned by the underlying Android or iOS plugin invocation.
17    #[cfg(mobile)]
18    #[error(transparent)]
19    PluginInvoke(
20        #[cfg_attr(feature = "specta", specta(skip))]
21        #[from]
22        tauri::plugin::mobile::PluginInvokeError,
23    ),
24}
25
26impl Serialize for Error {
27    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
28    where
29        S: Serializer,
30    {
31        serializer.serialize_str(self.to_string().as_ref())
32    }
33}