Skip to content

Commit 15e2d0a

Browse files
committed
fix: only look for fallback in parent dir on 404
If another error caused the file lookup to fail, bubble that error up instead.
1 parent c9ae7d5 commit 15e2d0a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/webserver/http.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -463,18 +463,29 @@ async fn serve_fallback(
463463
// Check if `maybe_fallback_path` actually exists, if not, skip to the next round (which
464464
// will check `maybe_fallback_path`s parent directory for fallback handler).
465465
let mabye_sql_path = PathBuf::from(&fallback_path_candidate);
466-
let Ok(sql_file) = app_state
466+
match app_state
467467
.sql_file_cache
468468
.get_with_privilege(app_state, &mabye_sql_path, false)
469469
.await
470-
else {
471-
log::trace!("The 404 handler {mabye_sql_path:?} does not exist");
472-
continue;
473-
};
470+
{
471+
// `maybe_fallback_path` does seem to exist, lets try to run it!
472+
Ok(sql_file) => {
473+
log::debug!("Processing SQL request via fallback: {:?}", mabye_sql_path);
474+
return render_sql(service_request, sql_file).await;
475+
}
476+
Err(e) => {
477+
let actix_web_err = anyhow_err_to_actix(e);
474478

475-
// `maybe_fallback_path` does seem to exist, lets try to run it!
476-
log::debug!("Processing SQL request via fallback: {:?}", mabye_sql_path);
477-
return render_sql(service_request, sql_file).await;
479+
// `maybe_fallback_path` does not exist, continue search in parent dir.
480+
if actix_web_err.as_response_error().status_code() == StatusCode::NOT_FOUND {
481+
log::trace!("The 404 handler {mabye_sql_path:?} does not exist");
482+
continue;
483+
}
484+
485+
// Another error occured, bubble it up!
486+
return Err(actix_web_err);
487+
}
488+
}
478489
}
479490

480491
log::debug!("There is no {catch_all:?} handler, this response is terminally failed");

0 commit comments

Comments
 (0)