From 5e2b8b376c07d1f16d7433611720ea6ac24aef17 Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 14 Aug 2023 16:20:28 +0100 Subject: [PATCH] utils: add ApiError::ShuttingDown So that handlers that check their CancellationToken explicitly can map it to a set http status. --- libs/utils/src/http/error.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/utils/src/http/error.rs b/libs/utils/src/http/error.rs index 527e486fd0..dd54cd6ecd 100644 --- a/libs/utils/src/http/error.rs +++ b/libs/utils/src/http/error.rs @@ -24,6 +24,9 @@ pub enum ApiError { #[error("Precondition failed: {0}")] PreconditionFailed(Box), + #[error("Shutting down")] + ShuttingDown, + #[error(transparent)] InternalServerError(anyhow::Error), } @@ -52,6 +55,10 @@ impl ApiError { self.to_string(), StatusCode::PRECONDITION_FAILED, ), + ApiError::ShuttingDown => HttpErrorBody::response_from_msg_and_status( + "Shutting down".to_string(), + StatusCode::SERVICE_UNAVAILABLE, + ), ApiError::InternalServerError(err) => HttpErrorBody::response_from_msg_and_status( err.to_string(), StatusCode::INTERNAL_SERVER_ERROR,