mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 06:10:44 +08:00
httpd: Separate Error types of git route and /raw
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
@@ -3,7 +3,7 @@ use axum::response::{IntoResponse, Response};
|
||||
use axum::Json;
|
||||
use serde_json::json;
|
||||
|
||||
/// Errors relating to the HTTP backend.
|
||||
/// Errors relating to the API backend.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
/// The entity was not found.
|
||||
|
||||
+36
-20
@@ -1,9 +1,9 @@
|
||||
use axum::http;
|
||||
use axum::response::{IntoResponse, Response};
|
||||
|
||||
/// Errors relating to the HTTP backend.
|
||||
/// Errors relating to the Git backend.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
pub enum GitError {
|
||||
/// The entity was not found.
|
||||
#[error("not found")]
|
||||
NotFound,
|
||||
@@ -24,10 +24,6 @@ pub enum Error {
|
||||
#[error("backend error")]
|
||||
Backend,
|
||||
|
||||
/// Id is not valid.
|
||||
#[error("id is not valid")]
|
||||
InvalidId,
|
||||
|
||||
/// HeaderName error.
|
||||
#[error(transparent)]
|
||||
InvalidHeaderName(#[from] axum::http::header::InvalidHeaderName),
|
||||
@@ -35,29 +31,49 @@ pub enum Error {
|
||||
/// HeaderValue error.
|
||||
#[error(transparent)]
|
||||
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 {
|
||||
match self {
|
||||
Error::ServiceUnavailable(_) => http::StatusCode::SERVICE_UNAVAILABLE,
|
||||
Error::InvalidId => http::StatusCode::NOT_FOUND,
|
||||
Error::Id(_) => http::StatusCode::NOT_FOUND,
|
||||
Error::NotFound => http::StatusCode::NOT_FOUND,
|
||||
GitError::ServiceUnavailable(_) => http::StatusCode::SERVICE_UNAVAILABLE,
|
||||
GitError::Id(_) => http::StatusCode::NOT_FOUND,
|
||||
GitError::NotFound => http::StatusCode::NOT_FOUND,
|
||||
_ => 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 {
|
||||
tracing::error!("{}", self);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ use hyper::body::Buf as _;
|
||||
use radicle::identity::Id;
|
||||
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 {
|
||||
Router::new()
|
||||
|
||||
@@ -13,7 +13,7 @@ use radicle::storage::git::paths;
|
||||
use radicle_surf::{Oid, Repository};
|
||||
|
||||
use crate::axum_extra::Path;
|
||||
use crate::error::Error;
|
||||
use crate::error::RawError as Error;
|
||||
|
||||
const MAX_BLOB_SIZE: usize = 4_194_304;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user