mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-01 23:42:33 +03:00
This commit is contained in:
parent
1886a9885e
commit
2a5ba7fe77
5
.changes/http-error-message.md
Normal file
5
.changes/http-error-message.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Add new `Http` variant to the `tauri::api::Error` enum, including status code and error message on the HTTP API error response.
|
@ -32,6 +32,9 @@ pub enum Error {
|
||||
#[cfg(feature = "reqwest-client")]
|
||||
#[error("Network Error: {0}")]
|
||||
Network(#[from] reqwest::Error),
|
||||
/// HTTP request error. First parameter is the response status code, and the second is the response text.
|
||||
#[error("HTTP Error: status code {0} and response `{1}`")]
|
||||
Http(u16, String),
|
||||
/// HTTP method error.
|
||||
#[error("{0}")]
|
||||
HttpMethod(#[from] http::method::InvalidMethod),
|
||||
|
@ -118,12 +118,18 @@ impl Client {
|
||||
request_builder.send()?
|
||||
};
|
||||
|
||||
let response = response.error_for_status()?;
|
||||
Ok(Response(
|
||||
request.response_type.unwrap_or(ResponseType::Json),
|
||||
response,
|
||||
request.url,
|
||||
))
|
||||
if response.is_success() {
|
||||
Ok(Response(
|
||||
request.response_type.unwrap_or(ResponseType::Json),
|
||||
response,
|
||||
request.url,
|
||||
))
|
||||
} else {
|
||||
Err(super::Error::Http(
|
||||
response.status().as_u16(),
|
||||
response.text()?,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,11 +190,17 @@ impl Client {
|
||||
request_builder.send().await?
|
||||
};
|
||||
|
||||
let response = response.error_for_status()?;
|
||||
Ok(Response(
|
||||
request.response_type.unwrap_or(ResponseType::Json),
|
||||
response,
|
||||
))
|
||||
if response.status().is_success() {
|
||||
Ok(Response(
|
||||
request.response_type.unwrap_or(ResponseType::Json),
|
||||
response,
|
||||
))
|
||||
} else {
|
||||
Err(super::Error::Http(
|
||||
response.status().as_u16(),
|
||||
response.text().await?,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user