httpd: Separate `Error` types of git route and `/raw`
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
parent
b80fc5437c
commit
3ee76c2891
|
|
@ -3,7 +3,7 @@ use axum::response::{IntoResponse, Response};
|
||||||
use axum::Json;
|
use axum::Json;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
/// Errors relating to the HTTP backend.
|
/// Errors relating to the API backend.
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// The entity was not found.
|
/// The entity was not found.
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
use axum::http;
|
use axum::http;
|
||||||
use axum::response::{IntoResponse, Response};
|
use axum::response::{IntoResponse, Response};
|
||||||
|
|
||||||
/// Errors relating to the HTTP backend.
|
/// Errors relating to the Git backend.
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum GitError {
|
||||||
/// The entity was not found.
|
/// The entity was not found.
|
||||||
#[error("not found")]
|
#[error("not found")]
|
||||||
NotFound,
|
NotFound,
|
||||||
|
|
@ -24,10 +24,6 @@ pub enum Error {
|
||||||
#[error("backend error")]
|
#[error("backend error")]
|
||||||
Backend,
|
Backend,
|
||||||
|
|
||||||
/// Id is not valid.
|
|
||||||
#[error("id is not valid")]
|
|
||||||
InvalidId,
|
|
||||||
|
|
||||||
/// HeaderName error.
|
/// HeaderName error.
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
InvalidHeaderName(#[from] axum::http::header::InvalidHeaderName),
|
InvalidHeaderName(#[from] axum::http::header::InvalidHeaderName),
|
||||||
|
|
@ -35,29 +31,49 @@ pub enum Error {
|
||||||
/// HeaderValue error.
|
/// HeaderValue error.
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
InvalidHeaderValue(#[from] axum::http::header::InvalidHeaderValue),
|
InvalidHeaderValue(#[from] axum::http::header::InvalidHeaderValue),
|
||||||
|
|
||||||
/// Surf error.
|
|
||||||
#[error(transparent)]
|
|
||||||
Surf(#[from] radicle_surf::Error),
|
|
||||||
|
|
||||||
// Surf file error.
|
|
||||||
#[error(transparent)]
|
|
||||||
SurfFile(#[from] radicle_surf::fs::error::File),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl GitError {
|
||||||
pub fn status(&self) -> http::StatusCode {
|
pub fn status(&self) -> http::StatusCode {
|
||||||
match self {
|
match self {
|
||||||
Error::ServiceUnavailable(_) => http::StatusCode::SERVICE_UNAVAILABLE,
|
GitError::ServiceUnavailable(_) => http::StatusCode::SERVICE_UNAVAILABLE,
|
||||||
Error::InvalidId => http::StatusCode::NOT_FOUND,
|
GitError::Id(_) => http::StatusCode::NOT_FOUND,
|
||||||
Error::Id(_) => http::StatusCode::NOT_FOUND,
|
GitError::NotFound => http::StatusCode::NOT_FOUND,
|
||||||
Error::NotFound => http::StatusCode::NOT_FOUND,
|
|
||||||
_ => http::StatusCode::INTERNAL_SERVER_ERROR,
|
_ => http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoResponse for Error {
|
impl IntoResponse for GitError {
|
||||||
|
fn into_response(self) -> Response {
|
||||||
|
tracing::error!("{}", self);
|
||||||
|
|
||||||
|
self.status().into_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Errors relating to the `/raw` route.
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum RawError {
|
||||||
|
/// Surf error.
|
||||||
|
#[error(transparent)]
|
||||||
|
Surf(#[from] radicle_surf::Error),
|
||||||
|
|
||||||
|
/// Surf file error.
|
||||||
|
#[error(transparent)]
|
||||||
|
SurfFile(#[from] radicle_surf::fs::error::File),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RawError {
|
||||||
|
pub fn status(&self) -> http::StatusCode {
|
||||||
|
match self {
|
||||||
|
RawError::SurfFile(_) => http::StatusCode::NOT_FOUND,
|
||||||
|
_ => http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoResponse for RawError {
|
||||||
fn into_response(self) -> Response {
|
fn into_response(self) -> Response {
|
||||||
tracing::error!("{}", self);
|
tracing::error!("{}", self);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ use hyper::body::Buf as _;
|
||||||
use radicle::identity::Id;
|
use radicle::identity::Id;
|
||||||
use radicle::profile::Profile;
|
use radicle::profile::Profile;
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::GitError as Error;
|
||||||
|
|
||||||
pub fn router(profile: Arc<Profile>, aliases: HashMap<String, Id>) -> Router {
|
pub fn router(profile: Arc<Profile>, aliases: HashMap<String, Id>) -> Router {
|
||||||
Router::new()
|
Router::new()
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ use radicle::storage::git::paths;
|
||||||
use radicle_surf::{Oid, Repository};
|
use radicle_surf::{Oid, Repository};
|
||||||
|
|
||||||
use crate::axum_extra::Path;
|
use crate::axum_extra::Path;
|
||||||
use crate::error::Error;
|
use crate::error::RawError as Error;
|
||||||
|
|
||||||
const MAX_BLOB_SIZE: usize = 4_194_304;
|
const MAX_BLOB_SIZE: usize = 4_194_304;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue