From 2b87ad09a79e64e4dd6f06457e476f792a7ac2de Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Sat, 31 Dec 2022 02:23:43 +0530 Subject: [PATCH] feat: handle reqwest errors --- src/conductor.rs | 3 +-- src/ctx/api/v1/forms.rs | 15 +++++---------- src/errors.rs | 10 ++++++++++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/conductor.rs b/src/conductor.rs index 57114cf..0b7d806 100644 --- a/src/conductor.rs +++ b/src/conductor.rs @@ -48,8 +48,7 @@ impl Conductor { .bearer_auth(&c.api_key) .json(e) .send() - .await - .unwrap(); + .await?; } Ok(()) } diff --git a/src/ctx/api/v1/forms.rs b/src/ctx/api/v1/forms.rs index 959ca20..5e67fe9 100644 --- a/src/ctx/api/v1/forms.rs +++ b/src/ctx/api/v1/forms.rs @@ -37,8 +37,7 @@ impl Ctx { .bearer_auth(&self.settings.form.api_key) .json(payload) .send() - .await - .unwrap(); + .await?; Ok(()) } @@ -60,11 +59,9 @@ impl Ctx { .bearer_auth(&self.settings.form.api_key) .json(payload) .send() - .await - .unwrap() + .await? .json() - .await - .unwrap(); + .await?; Ok(res) } @@ -84,11 +81,9 @@ impl Ctx { .get(form_url) .bearer_auth(&self.settings.form.api_key) .send() - .await - .unwrap() + .await? .json() - .await - .unwrap(); + .await?; Ok(res) } } diff --git a/src/errors.rs b/src/errors.rs index 42c2b96..67f244b 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -30,7 +30,9 @@ use derive_more::{Display, Error}; use git2::Error as GitError; use hmac::digest::InvalidLength; use hmac::digest::MacError; +use reqwest::Error as ReqwestError; use serde::{Deserialize, Serialize}; +use tracing::error; use url::ParseError; use crate::page::Page; @@ -186,6 +188,14 @@ pub enum ServiceError { WebhookNotFound, } +impl From for ServiceError { + #[cfg(not(tarpaulin_include))] + fn from(e: ReqwestError) -> ServiceError { + error!("{}", e); + ServiceError::InternalServerError + } +} + impl From for ServiceError { #[cfg(not(tarpaulin_include))] fn from(_: InvalidLength) -> ServiceError {