diff options
Diffstat (limited to 'src/errors.rs')
-rw-r--r-- | src/errors.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/errors.rs b/src/errors.rs index cbec046..f6e00e2 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,3 +1,5 @@ +use hex::FromHexError; +use ring::error::KeyRejected; use thiserror::Error; use axum::response::{Response, IntoResponse}; @@ -5,6 +7,8 @@ use axum::http::StatusCode; use axum::body; use axum::Json; +use ring::error::Unspecified as RingUnspecified; + #[derive(Debug, Error)] pub enum ServiceError { #[error("Solarlib error: {0}")] @@ -28,12 +32,25 @@ pub enum ServiceError { #[error("Generic: {0}")] Generic(String), - #[error("Paseto: {0}")] - Paseto(#[from] pasetors::errors::Error), + #[error("Invalid PASETO Key: {0}")] + PasetoInvalid(#[from] KeyRejected), +} + +impl From<FromHexError> for ServiceError { + fn from(_: FromHexError) -> Self { + ServiceError::Generic(String::from("Could not convert from hex")) + } } +impl From<RingUnspecified> for ServiceError { + fn from(_: RingUnspecified) -> Self { + ServiceError::Generic("Unspecified RNG error".to_string()) + } +} pub type StringResult<T = &'static str> = std::result::Result<T, ServiceError>; +pub type TokenResult<T = String> = std::result::Result<T, ServiceError>; + pub type JsonResult<T> = std::result::Result<T, ServiceError>; pub type NoneResult = std::result::Result<(), ServiceError>; |