mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-02 13:41:49 +02:00
feat(http): refactor and improvements (#428)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
+25
-10
@@ -2,10 +2,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use reqwest::Url;
|
||||
use serde::{Serialize, Serializer};
|
||||
use url::Url;
|
||||
|
||||
use crate::RequestId;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
@@ -15,19 +15,32 @@ pub enum Error {
|
||||
Io(#[from] std::io::Error),
|
||||
#[error(transparent)]
|
||||
Network(#[from] reqwest::Error),
|
||||
#[error(transparent)]
|
||||
Http(#[from] http::Error),
|
||||
#[error(transparent)]
|
||||
HttpInvalidHeaderName(#[from] http::header::InvalidHeaderName),
|
||||
#[error(transparent)]
|
||||
HttpInvalidHeaderValue(#[from] http::header::InvalidHeaderValue),
|
||||
/// URL not allowed by the scope.
|
||||
#[error("url not allowed on the configured scope: {0}")]
|
||||
UrlNotAllowed(Url),
|
||||
/// Path not allowed by the scope.
|
||||
#[error("path not allowed on the configured scope: {0}")]
|
||||
PathNotAllowed(PathBuf),
|
||||
/// Client with specified ID not found.
|
||||
#[error("http client dropped or not initialized")]
|
||||
HttpClientNotInitialized,
|
||||
#[error(transparent)]
|
||||
UrlParseError(#[from] url::ParseError),
|
||||
/// HTTP method error.
|
||||
#[error(transparent)]
|
||||
HttpMethod(#[from] http::method::InvalidMethod),
|
||||
/// Failed to serialize header value as string.
|
||||
#[error("scheme {0} not supported")]
|
||||
SchemeNotSupport(String),
|
||||
#[error("Request canceled")]
|
||||
RequestCanceled,
|
||||
#[error(transparent)]
|
||||
FsError(#[from] tauri_plugin_fs::Error),
|
||||
#[error("failed to process data url")]
|
||||
DataUrlError,
|
||||
#[error("failed to decode data url into bytes")]
|
||||
DataUrlDecodeError,
|
||||
#[error("invalid request id: {0}")]
|
||||
InvalidRequestId(RequestId),
|
||||
#[error(transparent)]
|
||||
Utf8(#[from] std::string::FromUtf8Error),
|
||||
}
|
||||
@@ -40,3 +53,5 @@ impl Serialize for Error {
|
||||
serializer.serialize_str(self.to_string().as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
Reference in New Issue
Block a user