2021-12-29 18:33:31 +01:00
|
|
|
use std::{convert::Infallible, string::FromUtf8Error};
|
|
|
|
|
|
|
|
use axum::{
|
|
|
|
body::{Bytes, Empty},
|
|
|
|
response::IntoResponse,
|
|
|
|
};
|
|
|
|
use reqwest::StatusCode;
|
2022-01-05 23:46:19 +01:00
|
|
|
use thiserror::Error;
|
|
|
|
|
2022-01-17 21:58:33 +01:00
|
|
|
use crate::error::ServiceError;
|
2022-01-05 23:46:19 +01:00
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum CDNError {
|
|
|
|
#[error("SQL error: {0}")]
|
2022-01-10 14:37:27 +01:00
|
|
|
Sql(#[from] sqlx::Error),
|
2022-01-17 21:58:33 +01:00
|
|
|
#[error("JMService error: {0}")]
|
|
|
|
Service(#[from] ServiceError),
|
2022-01-05 23:46:19 +01:00
|
|
|
#[error("Decode error: {0}")]
|
|
|
|
Decode(#[from] FromUtf8Error),
|
|
|
|
#[error("Internal server error")]
|
|
|
|
Internal,
|
2021-12-29 18:33:31 +01:00
|
|
|
}
|
|
|
|
|
2022-01-05 23:46:19 +01:00
|
|
|
impl IntoResponse for CDNError {
|
2021-12-29 18:33:31 +01:00
|
|
|
type Body = Empty<Bytes>;
|
|
|
|
|
|
|
|
type BodyError = Infallible;
|
|
|
|
|
|
|
|
fn into_response(self) -> axum::http::Response<Self::Body> {
|
2022-01-05 23:46:19 +01:00
|
|
|
let status = match self {
|
2022-01-10 14:37:27 +01:00
|
|
|
CDNError::Sql(sqlx::Error::RowNotFound) => StatusCode::NOT_FOUND,
|
2022-01-05 23:46:19 +01:00
|
|
|
_ => StatusCode::INTERNAL_SERVER_ERROR,
|
|
|
|
};
|
|
|
|
status.into_response()
|
2021-12-29 18:33:31 +01:00
|
|
|
}
|
|
|
|
}
|