From b3b714411dc06e162cfce1d28dfb09e9648cd9ea Mon Sep 17 00:00:00 2001 From: DeathwingTheBoss <ozcanbarisucar@gmail.com> Date: Thu, 9 Nov 2023 23:58:51 +0300 Subject: [PATCH] Beautify reqwest related errors --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a6912d..6d3896c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -585,7 +585,7 @@ checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" [[package]] name = "drone" -version = "0.2.5" +version = "0.2.6" dependencies = [ "actix-cors", "actix-web", diff --git a/Cargo.toml b/Cargo.toml index 9bd3feb..c152b39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "drone" -version = "0.2.5" +version = "0.2.6" edition = "2021" authors = ["Deathwing <hi@deathwing.me>"] description = "A caching reverse-proxy application for the Hive blockchain." diff --git a/src/main.rs b/src/main.rs index 43377a9..e09df4c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use reqwest::{Client, ClientBuilder}; use serde::{Deserialize, Serialize, Serializer}; use serde_json::Value; use serde_with::{serde_as, DurationSeconds}; -use std::{sync::Mutex, time::Duration}; +use std::{sync::Mutex, time::Duration, fmt::Display}; const DRONE_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -110,6 +110,16 @@ impl Endpoints { } } +impl Display for Endpoints { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Endpoints::HAF => write!(f, " Endpoint: HAF"), + Endpoints::HAFAH => write!(f, " Endpoint: HAFAH"), + Endpoints::HIVEMIND => write!(f, " Endpoint: HIVEMIND"), + } + } +} + #[async_recursion] async fn handle_request( request: &APIRequest, @@ -221,12 +231,14 @@ async fn handle_request( { Ok(response) => response, Err(err) => { + let mut error_message = err.without_url().to_string(); + error_message.push_str(&endpoints.to_string()); return Err(ErrorStructure { jsonrpc: request.jsonrpc.clone(), id : request.id, code: -32700, message: format!("Unable to send request to endpoint."), - error: ErrorField::Message(err.to_string()), + error: ErrorField::Message(error_message), }) } }; -- GitLab