Skip to content

Commit bab315b

Browse files
authored
Merge pull request #6 from fpco/display-error
display_error method
2 parents 5a324a1 + 69e8a62 commit bab315b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff 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

284291
impl 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(),

0 commit comments

Comments
 (0)