mirror of
https://github.com/speatzle/nfsense.git
synced 2025-09-13 15:19:08 +00:00
switch from custom_error to thiserror
This commit is contained in:
parent
c10f5529d6
commit
7fcf84f62e
5 changed files with 41 additions and 24 deletions
|
@ -12,12 +12,19 @@ use jsonrpsee::{
|
|||
RpcModule,
|
||||
};
|
||||
|
||||
use custom_error::custom_error;
|
||||
use thiserror::Error;
|
||||
use tracing::info;
|
||||
|
||||
custom_error! { pub ApiError
|
||||
InvalidParams = "Invalid Parameters",
|
||||
Leet = "1337",
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ApiError {
|
||||
#[error("Unsupported config version")]
|
||||
InvalidParams,
|
||||
|
||||
#[error("1337")]
|
||||
Leet,
|
||||
|
||||
#[error(transparent)]
|
||||
ConfigError(#[from] crate::config_manager::ConfigError),
|
||||
}
|
||||
|
||||
impl Into<ErrorObject<'static>> for ApiError {
|
||||
|
|
|
@ -7,18 +7,30 @@ use std::fs;
|
|||
use std::sync::{Arc, Mutex, MutexGuard};
|
||||
use std::{io, result::Result};
|
||||
|
||||
use custom_error::custom_error;
|
||||
|
||||
use pwhash::sha512_crypt;
|
||||
|
||||
custom_error! { pub ConfigError
|
||||
IoError{source: io::Error} = "io error",
|
||||
SerdeError{source: serde_json::Error} = "serde json error",
|
||||
ValidatonError{source: validator::ValidationErrors} = "validation failed",
|
||||
HashError{source: pwhash::error::Error} = "password hash generation",
|
||||
UnsupportedVersionError = "unsupported config version",
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ConfigError {
|
||||
#[error("Json Error")]
|
||||
SerdeError(#[from] serde_json::Error),
|
||||
|
||||
#[error("Validation Error")]
|
||||
ValidatonError(#[from] validator::ValidationErrors),
|
||||
|
||||
#[error("Hash Error")]
|
||||
HashError(#[from] pwhash::error::Error),
|
||||
|
||||
#[error("Unsupported config version")]
|
||||
UnsupportedVersionError,
|
||||
|
||||
/// Represents all other cases of `std::io::Error`.
|
||||
#[error(transparent)]
|
||||
IOError(#[from] std::io::Error),
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO do Error conversion
|
||||
impl Into<ApiError> for ConfigError {
|
||||
fn into(self) -> ApiError {
|
||||
|
@ -26,6 +38,8 @@ impl Into<ApiError> for ConfigError {
|
|||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
pub const CURRENT_CONFIG_PATH: &str = "config.json";
|
||||
pub const PENDING_CONFIG_PATH: &str = "pending.json";
|
||||
|
||||
|
|
|
@ -21,11 +21,15 @@ use axum::{
|
|||
use pwhash::sha512_crypt;
|
||||
use tracing::info;
|
||||
|
||||
use custom_error::custom_error;
|
||||
use thiserror::Error;
|
||||
|
||||
custom_error! { AuthError
|
||||
NoSessionCookie = "No Session Cookie Found",
|
||||
InvalidSession = "Invalid Session"
|
||||
#[derive(Error, Debug)]
|
||||
pub enum AuthError {
|
||||
#[error("No Session Cookie Found")]
|
||||
NoSessionCookie,
|
||||
|
||||
#[error("Invalid Session")]
|
||||
InvalidSession,
|
||||
}
|
||||
|
||||
const SESSION_COOKIE: &str = "session";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue