tauri_plugin_http/
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, Serializer};
6use url::Url;
7
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10    #[error(transparent)]
11    Json(#[from] serde_json::Error),
12    #[error(transparent)]
13    Io(#[from] std::io::Error),
14    #[error(transparent)]
15    Network(#[from] reqwest::Error),
16    #[error(transparent)]
17    Http(#[from] http::Error),
18    #[error(transparent)]
19    HttpInvalidHeaderName(#[from] http::header::InvalidHeaderName),
20    #[error(transparent)]
21    HttpInvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
22    /// URL not allowed by the scope.
23    #[error("url not allowed on the configured scope: {0}")]
24    UrlNotAllowed(Url),
25    #[error(transparent)]
26    UrlParseError(#[from] url::ParseError),
27    /// HTTP method error.
28    #[error(transparent)]
29    HttpMethod(#[from] http::method::InvalidMethod),
30    #[error("scheme {0} not supported")]
31    SchemeNotSupport(String),
32    #[error("Request canceled")]
33    RequestCanceled,
34    #[error(transparent)]
35    FsError(#[from] tauri_plugin_fs::Error),
36    #[error("failed to process data url")]
37    DataUrlError,
38    #[error("failed to decode data url into bytes")]
39    DataUrlDecodeError,
40    #[error(transparent)]
41    Tauri(#[from] tauri::Error),
42    #[error(transparent)]
43    Utf8(#[from] std::string::FromUtf8Error),
44    #[error("dangerous settings used but are not enabled")]
45    DangerousSettings,
46}
47
48impl Serialize for Error {
49    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
50    where
51        S: Serializer,
52    {
53        serializer.serialize_str(self.to_string().as_ref())
54    }
55}
56
57pub type Result<T> = std::result::Result<T, Error>;