From b5af6ef549cdd7a3212549edb1737ed6c12b7a28 Mon Sep 17 00:00:00 2001 From: Evan <0xIchigo@protonmail.com> Date: Wed, 17 Apr 2024 16:44:12 -0400 Subject: [PATCH] Create error.rs and Add Basic Errors --- src/error.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/error.rs diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..bcca61a --- /dev/null +++ b/src/error.rs @@ -0,0 +1,25 @@ +use reqwest::{ Error as ReqwestError, StatusCode }; +use serde_json::Error as SerdeError; +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum HeliusError { + #[error("Bad request to {path}: {text}")] + BadRequest { path: String, text: String }, + + #[error("Internal server error: {code} - {text}")] + InternalError { code: StatusCode, text: String}, + + #[error("Too many requests made to {path}")] + TooManyRequests { path: String }, + + #[error("Unauthorized access to {path}: {text}")] + Unauthorized { path: String, text: String }, + + #[error("Unknown error has occurred: HTTP {code} - {text}")] + Unknown { code: StatusCode, text: String }, +} + + +// Handy type alias +pub type Result = std::result::Result; \ No newline at end of file