use thiserror::Error;
#[derive(Debug, Error)]
pub enum GitError {
#[error("path traversal or invalid path: {0}")]
PathTraversal(String),
#[error("unauthorised: {0}")]
Unauthorised(String),
#[error("not a git repository: {0}")]
NotARepository(String),
#[error("git-http-backend binary not available: {0}")]
BackendNotAvailable(String),
#[error("git backend failed: exit={exit_code:?}, stderr={stderr}")]
BackendFailed {
exit_code: Option<i32>,
stderr: String,
},
#[error("malformed CGI output: {0}")]
MalformedCgi(String),
#[error("i/o: {0}")]
Io(#[from] std::io::Error),
#[error("auth: {0}")]
Auth(#[from] crate::auth::AuthError),
}
impl GitError {
#[must_use]
pub fn status_code(&self) -> u16 {
match self {
GitError::PathTraversal(_) => 400,
GitError::Unauthorised(_) | GitError::Auth(_) => 401,
GitError::NotARepository(_) => 404,
GitError::BackendNotAvailable(_)
| GitError::BackendFailed { .. }
| GitError::MalformedCgi(_)
| GitError::Io(_) => 500,
}
}
}