-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
funds-manager: Refactor into HTTP server setup
- Loading branch information
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//! Error types for the funds manager | ||
|
||
use std::{error::Error, fmt::Display}; | ||
|
||
use warp::reject::Reject; | ||
|
||
/// The error type emitted by the funds manager | ||
#[derive(Debug, Clone)] | ||
pub enum FundsManagerError { | ||
/// An error with the arbitrum client | ||
Arbitrum(String), | ||
/// An error with a database query | ||
Db(String), | ||
/// An error executing an HTTP request | ||
Http(String), | ||
/// An error parsing a value | ||
Parse(String), | ||
/// An error with AWS secrets manager | ||
SecretsManager(String), | ||
/// A miscellaneous error | ||
Custom(String), | ||
} | ||
|
||
impl FundsManagerError { | ||
/// Create an arbitrum error | ||
pub fn arbitrum<T: ToString>(msg: T) -> FundsManagerError { | ||
Check failure on line 26 in funds-manager/src/error.rs GitHub Actions / clippythis argument is passed by value, but not consumed in the function body
|
||
FundsManagerError::Arbitrum(msg.to_string()) | ||
} | ||
|
||
/// Create a database error | ||
pub fn db<T: ToString>(msg: T) -> FundsManagerError { | ||
Check failure on line 31 in funds-manager/src/error.rs GitHub Actions / clippythis argument is passed by value, but not consumed in the function body
|
||
FundsManagerError::Db(msg.to_string()) | ||
} | ||
|
||
/// Create an HTTP error | ||
pub fn http<T: ToString>(msg: T) -> FundsManagerError { | ||
Check failure on line 36 in funds-manager/src/error.rs GitHub Actions / clippythis argument is passed by value, but not consumed in the function body
|
||
FundsManagerError::Http(msg.to_string()) | ||
} | ||
|
||
/// Create a parse error | ||
pub fn parse<T: ToString>(msg: T) -> FundsManagerError { | ||
Check failure on line 41 in funds-manager/src/error.rs GitHub Actions / clippythis argument is passed by value, but not consumed in the function body
|
||
FundsManagerError::Parse(msg.to_string()) | ||
} | ||
|
||
/// Create a secrets manager error | ||
pub fn secrets_manager<T: ToString>(msg: T) -> FundsManagerError { | ||
Check failure on line 46 in funds-manager/src/error.rs GitHub Actions / clippythis argument is passed by value, but not consumed in the function body
|
||
FundsManagerError::SecretsManager(msg.to_string()) | ||
} | ||
|
||
/// Create a custom error | ||
pub fn custom<T: ToString>(msg: T) -> FundsManagerError { | ||
Check failure on line 51 in funds-manager/src/error.rs GitHub Actions / clippythis argument is passed by value, but not consumed in the function body
|
||
FundsManagerError::Custom(msg.to_string()) | ||
} | ||
} | ||
|
||
impl Display for FundsManagerError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
FundsManagerError::Arbitrum(e) => write!(f, "Arbitrum error: {}", e), | ||
FundsManagerError::Db(e) => write!(f, "Database error: {}", e), | ||
FundsManagerError::Http(e) => write!(f, "HTTP error: {}", e), | ||
FundsManagerError::Parse(e) => write!(f, "Parse error: {}", e), | ||
FundsManagerError::SecretsManager(e) => write!(f, "Secrets manager error: {}", e), | ||
FundsManagerError::Custom(e) => write!(f, "Custom error: {}", e), | ||
} | ||
} | ||
} | ||
impl Error for FundsManagerError {} | ||
impl Reject for FundsManagerError {} |