diff --git a/backend/crates/gateway-core/src/concurrency.rs b/backend/crates/gateway-core/src/concurrency.rs index 41cc56eb7..c24ebe419 100644 --- a/backend/crates/gateway-core/src/concurrency.rs +++ b/backend/crates/gateway-core/src/concurrency.rs @@ -408,14 +408,8 @@ impl QueueRejection { #[must_use] pub fn gateway_error(self) -> crate::error::GatewayError { match self { - Self::Full => crate::error::GatewayError::new( - crate::error::GatewayErrorKind::ConcurrencyQueueFull, - "The gateway request queue is full.", - ), - Self::Timeout => crate::error::GatewayError::new( - crate::error::GatewayErrorKind::ConcurrencyQueueTimeout, - "The request timed out in the gateway queue.", - ), + Self::Full => crate::error::GatewayError::concurrency_queue_full(), + Self::Timeout => crate::error::GatewayError::concurrency_queue_timeout(), } } } diff --git a/backend/crates/gateway-core/src/error/mod.rs b/backend/crates/gateway-core/src/error/mod.rs index b674e57b3..75c2cfaf7 100644 --- a/backend/crates/gateway-core/src/error/mod.rs +++ b/backend/crates/gateway-core/src/error/mod.rs @@ -1381,6 +1381,20 @@ impl GatewayError { } } + pub(crate) const fn concurrency_queue_full() -> Self { + Self::new( + GatewayErrorKind::ConcurrencyQueueFull, + "The gateway request queue is full.", + ) + } + + pub(crate) const fn concurrency_queue_timeout() -> Self { + Self::new( + GatewayErrorKind::ConcurrencyQueueTimeout, + "The request timed out in the gateway queue.", + ) + } + #[must_use] pub fn with_source(mut self, source: impl Into) -> Self { self.source = Some(source.into()); @@ -1469,12 +1483,8 @@ impl GatewayError { GatewayErrorKind::AccountPoolQuotaExhausted, "No eligible gateway account has quota for this request.", ), - ProviderErrorKind::ConcurrencyQueueFull => { - crate::concurrency::QueueRejection::Full.gateway_error() - } - ProviderErrorKind::ConcurrencyQueueTimeout => { - crate::concurrency::QueueRejection::Timeout.gateway_error() - } + ProviderErrorKind::ConcurrencyQueueFull => Self::concurrency_queue_full(), + ProviderErrorKind::ConcurrencyQueueTimeout => Self::concurrency_queue_timeout(), ProviderErrorKind::AccountCapacityUnavailable => Self::new( GatewayErrorKind::AccountCapacityUnavailable, "The gateway account pool is busy.",