File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,13 @@ pub trait CacheLoader: Send + Sync + 'static {
279279 fn into_response ( output : & Self :: Output ) -> Response < Body > {
280280 Json ( output) . into_response ( )
281281 }
282+
283+ /// Convert the error output into an error message and status code.
284+ ///
285+ /// By default, uses the [Display] trait and an internal server error (500 status code).
286+ fn display_error ( err : anyhow:: Error ) -> ( String , StatusCode ) {
287+ ( err. to_string ( ) , StatusCode :: INTERNAL_SERVER_ERROR )
288+ }
282289}
283290
284291impl AsyncLoaderBuilder {
@@ -595,7 +602,7 @@ impl<Loader: CacheLoader> AsyncLoader<Loader> {
595602 tracing:: error!( "AsyncLoader::do_update: {err:?}" ) ;
596603 let ( message, status) = match err. downcast ( ) {
597604 Ok ( ErrorResponse { status, message } ) => ( message, status) ,
598- Err ( err) => ( err . to_string ( ) , StatusCode :: INTERNAL_SERVER_ERROR ) ,
605+ Err ( err) => Loader :: display_error ( err ) ,
599606 } ;
600607 ValueForRender :: Error {
601608 message : message. into ( ) ,
You can’t perform that action at this time.
0 commit comments