@@ -3,7 +3,7 @@ use crate::webserver::database::{stream_query_results, DbItem};
33use crate :: webserver:: ErrorWithStatus ;
44use crate :: { AppState , Config , ParsedSqlFile } ;
55use actix_web:: dev:: { fn_service, ServiceFactory , ServiceRequest } ;
6- use actix_web:: error:: { ErrorInternalServerError , ErrorNotFound } ;
6+ use actix_web:: error:: ErrorInternalServerError ;
77use actix_web:: http:: header:: { ContentType , Header , HttpDate , IfModifiedSince , LastModified } ;
88use actix_web:: http:: { header, StatusCode , Uri } ;
99use actix_web:: web:: Form ;
@@ -411,24 +411,21 @@ async fn process_sql_request(
411411 . sql_file_cache
412412 . get ( app_state, & sql_path)
413413 . await
414- . map_err ( |e| {
415- log:: error!( "Error while trying to get SQL file: {:#}" , e) ;
416- if e. downcast_ref ( )
417- == Some ( & ErrorWithStatus {
418- status : StatusCode :: NOT_FOUND ,
419- } )
420- {
421- ErrorNotFound ( "The requested file was not found." )
422- } else {
423- ErrorInternalServerError ( format ! (
424- "An error occurred while trying to handle your request: {e:#}"
425- ) )
426- }
427- } ) ?;
414+ . map_err ( anyhow_err_to_actix) ?;
428415 let response = render_sql ( & mut req, sql_file) . await ?;
429416 Ok ( req. into_response ( response) )
430417}
431418
419+ fn anyhow_err_to_actix ( e : anyhow:: Error ) -> actix_web:: Error {
420+ log:: error!( "Error while trying to get SQL file: {:#}" , e) ;
421+ match e. downcast :: < ErrorWithStatus > ( ) {
422+ Ok ( err) => actix_web:: Error :: from ( err) ,
423+ Err ( e) => ErrorInternalServerError ( format ! (
424+ "An error occurred while trying to handle your request: {e:#}"
425+ ) ) ,
426+ }
427+ }
428+
432429async fn serve_file (
433430 path : & str ,
434431 state : & AppState ,
@@ -441,7 +438,7 @@ async fn serve_file(
441438 . file_system
442439 . modified_since ( state, path. as_ref ( ) , since, false )
443440 . await
444- . map_err ( actix_web :: error :: ErrorBadRequest ) ?;
441+ . map_err ( anyhow_err_to_actix ) ?;
445442 if !modified {
446443 return Ok ( HttpResponse :: NotModified ( ) . finish ( ) ) ;
447444 }
@@ -450,7 +447,7 @@ async fn serve_file(
450447 . file_system
451448 . read_file ( state, path. as_ref ( ) , false )
452449 . await
453- . map_err ( actix_web :: error :: ErrorBadRequest )
450+ . map_err ( anyhow_err_to_actix )
454451 . map ( |b| {
455452 HttpResponse :: Ok ( )
456453 . insert_header (
0 commit comments