Skip to content

Commit

Permalink
feat(serve): 404 for document not found
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Dec 5, 2024
1 parent 5f0f7e6 commit 3435feb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crates/rari-cli/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,23 @@ fn get_search_index(locale: Locale) -> Result<Vec<SearchItem>, DocError> {
}

#[derive(Debug)]
struct AppError(anyhow::Error);
struct AppError(DocError);

impl IntoResponse for AppError {
fn into_response(self) -> Response<Body> {
(StatusCode::INTERNAL_SERVER_ERROR, error!("🤷: {}", self.0)).into_response()
match self.0 {
DocError::RariIoError(_) | DocError::IOError(_) | DocError::PageNotFound(_, _) => {
(StatusCode::NOT_FOUND, "").into_response()
}

_ => (StatusCode::INTERNAL_SERVER_ERROR, error!("🤷: {}", self.0)).into_response(),
}
}
}

impl<E> From<E> for AppError
where
E: Into<anyhow::Error>,
E: Into<DocError>,
{
fn from(err: E) -> Self {
Self(err.into())
Expand Down

0 comments on commit 3435feb

Please sign in to comment.