jmserver/src/cdn/error.rs
Timo Ley b42e35da45
All checks were successful
ci/woodpecker/push/central-override Pipeline was successful
continuous-integration/drone/push Build is passing
feat: return IPFS header for CDN
2023-07-26 17:36:04 +02:00

40 lines
997 B
Rust

use std::{convert::Infallible, string::FromUtf8Error};
use axum::{
body::{Bytes, Empty},
response::IntoResponse,
};
use hyper::header::InvalidHeaderValue;
use reqwest::StatusCode;
use thiserror::Error;
use crate::error::ServiceError;
#[derive(Error, Debug)]
pub enum CDNError {
#[error("SQL error: {0}")]
Sql(#[from] sqlx::Error),
#[error("JMService error: {0}")]
Service(#[from] ServiceError),
#[error("Decode error: {0}")]
Decode(#[from] FromUtf8Error),
#[error("Header error: {0}")]
Header(#[from] InvalidHeaderValue),
#[error("Internal server error")]
Internal,
}
impl IntoResponse for CDNError {
type Body = Empty<Bytes>;
type BodyError = Infallible;
fn into_response(self) -> axum::http::Response<Self::Body> {
let status = match self {
CDNError::Sql(sqlx::Error::RowNotFound) => StatusCode::NOT_FOUND,
_ => StatusCode::INTERNAL_SERVER_ERROR,
};
status.into_response()
}
}