feat: add error message to HttpStatus error
dont create reports on http status errors
This commit is contained in:
parent
cc50862408
commit
fe76b2ac66
3 changed files with 14 additions and 22 deletions
|
|
@ -25,9 +25,9 @@ impl RustyPipeQuery {
|
||||||
.http_request_txt(self.client.inner.http.get(&url).build()?)
|
.http_request_txt(self.client.inner.http.get(&url).build()?)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| match e {
|
.map_err(|e| match e {
|
||||||
Error::HttpStatus(404) => Error::Extraction(ExtractionError::ContentUnavailable(
|
Error::HttpStatus(404, _) => Error::Extraction(
|
||||||
"Channel not found".into(),
|
ExtractionError::ContentUnavailable("Channel not found".into()),
|
||||||
)),
|
),
|
||||||
_ => e,
|
_ => e,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -538,7 +538,7 @@ impl RustyPipe {
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
|
|
||||||
if status.is_client_error() || status.is_server_error() {
|
if status.is_client_error() || status.is_server_error() {
|
||||||
Err(Error::HttpStatus(status.into()))
|
Err(Error::HttpStatus(status.into(), "none".into()))
|
||||||
} else {
|
} else {
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
@ -1086,26 +1086,18 @@ impl RustyPipeQuery {
|
||||||
};
|
};
|
||||||
|
|
||||||
if status.is_client_error() || status.is_server_error() {
|
if status.is_client_error() || status.is_server_error() {
|
||||||
let status_code = status.as_u16();
|
let error_msg = serde_json::from_str::<response::ErrorResponse>(&resp_str)
|
||||||
|
.map(|r| r.error.message)
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
return match status {
|
return match status {
|
||||||
StatusCode::NOT_FOUND => Err(Error::Extraction(
|
StatusCode::NOT_FOUND => Err(Error::Extraction(
|
||||||
ExtractionError::ContentUnavailable("404 Not found".into()),
|
ExtractionError::ContentUnavailable(error_msg.into()),
|
||||||
)),
|
)),
|
||||||
StatusCode::BAD_REQUEST => {
|
StatusCode::BAD_REQUEST => Err(Error::Extraction(ExtractionError::BadRequest(
|
||||||
let error_res = serde_json::from_str::<response::ErrorResponse>(&resp_str);
|
error_msg.into(),
|
||||||
Err(Error::Extraction(ExtractionError::BadRequest(
|
))),
|
||||||
error_res
|
_ => Err(Error::HttpStatus(status.as_u16(), error_msg.into())),
|
||||||
.map(|r| r.error.message)
|
|
||||||
.unwrap_or_default()
|
|
||||||
.into(),
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
let e = Error::HttpStatus(status_code);
|
|
||||||
create_report(Level::ERR, Some(e.to_string()), vec![]);
|
|
||||||
Err(e)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ pub enum Error {
|
||||||
#[error("http error: {0}")]
|
#[error("http error: {0}")]
|
||||||
Http(#[from] reqwest::Error),
|
Http(#[from] reqwest::Error),
|
||||||
/// Erroneous HTTP status code received
|
/// Erroneous HTTP status code received
|
||||||
#[error("http status code: {0}")]
|
#[error("http status code: {0} message: {1}")]
|
||||||
HttpStatus(u16),
|
HttpStatus(u16, Cow<'static, str>),
|
||||||
/// Unspecified error
|
/// Unspecified error
|
||||||
#[error("error: {0}")]
|
#[error("error: {0}")]
|
||||||
Other(Cow<'static, str>),
|
Other(Cow<'static, str>),
|
||||||
|
|
|
||||||
Reference in a new issue