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()?)
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
Error::HttpStatus(404) => Error::Extraction(ExtractionError::ContentUnavailable(
|
||||
"Channel not found".into(),
|
||||
)),
|
||||
Error::HttpStatus(404, _) => Error::Extraction(
|
||||
ExtractionError::ContentUnavailable("Channel not found".into()),
|
||||
),
|
||||
_ => e,
|
||||
})?;
|
||||
|
||||
|
|
|
|||
|
|
@ -538,7 +538,7 @@ impl RustyPipe {
|
|||
let status = res.status();
|
||||
|
||||
if status.is_client_error() || status.is_server_error() {
|
||||
Err(Error::HttpStatus(status.into()))
|
||||
Err(Error::HttpStatus(status.into(), "none".into()))
|
||||
} else {
|
||||
Ok(res)
|
||||
}
|
||||
|
|
@ -1086,26 +1086,18 @@ impl RustyPipeQuery {
|
|||
};
|
||||
|
||||
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 {
|
||||
StatusCode::NOT_FOUND => Err(Error::Extraction(
|
||||
ExtractionError::ContentUnavailable("404 Not found".into()),
|
||||
ExtractionError::ContentUnavailable(error_msg.into()),
|
||||
)),
|
||||
StatusCode::BAD_REQUEST => {
|
||||
let error_res = serde_json::from_str::<response::ErrorResponse>(&resp_str);
|
||||
Err(Error::Extraction(ExtractionError::BadRequest(
|
||||
error_res
|
||||
.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)
|
||||
}
|
||||
StatusCode::BAD_REQUEST => Err(Error::Extraction(ExtractionError::BadRequest(
|
||||
error_msg.into(),
|
||||
))),
|
||||
_ => Err(Error::HttpStatus(status.as_u16(), error_msg.into())),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ pub enum Error {
|
|||
#[error("http error: {0}")]
|
||||
Http(#[from] reqwest::Error),
|
||||
/// Erroneous HTTP status code received
|
||||
#[error("http status code: {0}")]
|
||||
HttpStatus(u16),
|
||||
#[error("http status code: {0} message: {1}")]
|
||||
HttpStatus(u16, Cow<'static, str>),
|
||||
/// Unspecified error
|
||||
#[error("error: {0}")]
|
||||
Other(Cow<'static, str>),
|
||||
|
|
|
|||
Reference in a new issue