2024-07-30 11:37:54 +01:00
|
|
|
use actix_web::{body::BoxBody, HttpResponse, ResponseError};
|
|
|
|
use log::error;
|
2024-11-10 15:43:25 +00:00
|
|
|
use pesde::source::git_index::errors::{ReadFile, RefreshError, TreeError};
|
2024-07-30 11:37:54 +01:00
|
|
|
use serde::Serialize;
|
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
#[derive(Debug, Error)]
|
|
|
|
pub enum Error {
|
|
|
|
#[error("failed to parse query")]
|
|
|
|
Query(#[from] tantivy::query::QueryParserError),
|
|
|
|
|
|
|
|
#[error("error reading repo file")]
|
|
|
|
ReadFile(#[from] ReadFile),
|
|
|
|
|
|
|
|
#[error("error deserializing file")]
|
|
|
|
Deserialize(#[from] toml::de::Error),
|
|
|
|
|
|
|
|
#[error("error sending request")]
|
|
|
|
Reqwest(#[from] reqwest::Error),
|
|
|
|
|
|
|
|
#[error("failed to parse archive entries")]
|
|
|
|
Tar(#[from] std::io::Error),
|
|
|
|
|
|
|
|
#[error("invalid archive")]
|
|
|
|
InvalidArchive,
|
|
|
|
|
|
|
|
#[error("failed to read index config")]
|
|
|
|
Config(#[from] pesde::source::pesde::errors::ConfigError),
|
|
|
|
|
|
|
|
#[error("git error")]
|
|
|
|
Git(#[from] git2::Error),
|
|
|
|
|
|
|
|
#[error("failed to refresh source")]
|
2024-08-08 16:59:59 +01:00
|
|
|
Refresh(#[from] Box<RefreshError>),
|
2024-07-30 11:37:54 +01:00
|
|
|
|
|
|
|
#[error("failed to serialize struct")]
|
|
|
|
Serialize(#[from] toml::ser::Error),
|
|
|
|
|
|
|
|
#[error("failed to serialize struct")]
|
|
|
|
SerializeJson(#[from] serde_json::Error),
|
2024-11-10 15:43:25 +00:00
|
|
|
|
|
|
|
#[error("failed to open git repo")]
|
|
|
|
OpenRepo(#[from] gix::open::Error),
|
|
|
|
|
|
|
|
#[error("failed to get root tree")]
|
|
|
|
RootTree(#[from] TreeError),
|
2024-07-30 11:37:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub struct ErrorResponse {
|
|
|
|
pub error: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ResponseError for Error {
|
|
|
|
fn error_response(&self) -> HttpResponse<BoxBody> {
|
|
|
|
match self {
|
|
|
|
Error::Query(e) => HttpResponse::BadRequest().json(ErrorResponse {
|
|
|
|
error: format!("failed to parse query: {e}"),
|
|
|
|
}),
|
2024-10-25 11:07:07 +01:00
|
|
|
Error::Tar(_) | Error::InvalidArchive => {
|
|
|
|
HttpResponse::BadRequest().json(ErrorResponse {
|
|
|
|
error: "invalid archive".to_string(),
|
|
|
|
})
|
|
|
|
}
|
2024-07-30 11:37:54 +01:00
|
|
|
e => {
|
|
|
|
log::error!("unhandled error: {e:?}");
|
|
|
|
HttpResponse::InternalServerError().finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|