feat: handle reqwest errors
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Aravinth Manivannan 2022-12-31 02:23:43 +05:30
parent 86d56734cf
commit 2b87ad09a7
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
3 changed files with 16 additions and 12 deletions

View file

@ -48,8 +48,7 @@ impl Conductor {
.bearer_auth(&c.api_key) .bearer_auth(&c.api_key)
.json(e) .json(e)
.send() .send()
.await .await?;
.unwrap();
} }
Ok(()) Ok(())
} }

View file

@ -37,8 +37,7 @@ impl Ctx {
.bearer_auth(&self.settings.form.api_key) .bearer_auth(&self.settings.form.api_key)
.json(payload) .json(payload)
.send() .send()
.await .await?;
.unwrap();
Ok(()) Ok(())
} }
@ -60,11 +59,9 @@ impl Ctx {
.bearer_auth(&self.settings.form.api_key) .bearer_auth(&self.settings.form.api_key)
.json(payload) .json(payload)
.send() .send()
.await .await?
.unwrap()
.json() .json()
.await .await?;
.unwrap();
Ok(res) Ok(res)
} }
@ -84,11 +81,9 @@ impl Ctx {
.get(form_url) .get(form_url)
.bearer_auth(&self.settings.form.api_key) .bearer_auth(&self.settings.form.api_key)
.send() .send()
.await .await?
.unwrap()
.json() .json()
.await .await?;
.unwrap();
Ok(res) Ok(res)
} }
} }

View file

@ -30,7 +30,9 @@ use derive_more::{Display, Error};
use git2::Error as GitError; use git2::Error as GitError;
use hmac::digest::InvalidLength; use hmac::digest::InvalidLength;
use hmac::digest::MacError; use hmac::digest::MacError;
use reqwest::Error as ReqwestError;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::error;
use url::ParseError; use url::ParseError;
use crate::page::Page; use crate::page::Page;
@ -186,6 +188,14 @@ pub enum ServiceError {
WebhookNotFound, WebhookNotFound,
} }
impl From<ReqwestError> for ServiceError {
#[cfg(not(tarpaulin_include))]
fn from(e: ReqwestError) -> ServiceError {
error!("{}", e);
ServiceError::InternalServerError
}
}
impl From<InvalidLength> for ServiceError { impl From<InvalidLength> for ServiceError {
#[cfg(not(tarpaulin_include))] #[cfg(not(tarpaulin_include))]
fn from(_: InvalidLength) -> ServiceError { fn from(_: InvalidLength) -> ServiceError {