Lines
0 %
Functions
Branches
100 %
use std::path::PathBuf;
use actix_http::error::PayloadError;
use actix_web::{http::header::ContentType, HttpResponse};
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Error on {path}: {source}")]
Io {
source: std::io::Error,
path: PathBuf,
},
Utf8 {
source: std::string::FromUtf8Error,
#[error("Authentication error: {source}")]
Authentication {
#[from]
source: jsonwebtoken::errors::Error,
#[error("Error on {path:?}: {source}")]
Serde {
source: serde_json::Error,
path: Option<PathBuf>,
#[error("{source}")]
Payload {
source: PayloadError,
#[error("Error: {0}")]
Msg(String),
#[error(transparent)]
Other(#[from] Box<dyn std::error::Error>),
}
impl actix_web::error::ResponseError for Error {
fn error_response(&self) -> HttpResponse {
let msg = self.to_string();
HttpResponse::build(self.status_code())
.insert_header(ContentType::html())
.body(msg)
pub type Result<T> = std::result::Result<T, Error>;