diff --git a/src/push_service/error.rs b/src/push_service/error.rs index 3b3cb420c..c2ba7ca76 100644 --- a/src/push_service/error.rs +++ b/src/push_service/error.rs @@ -96,6 +96,9 @@ pub enum ServiceError { #[error("Unknown CDN version {0}")] UnknownCdnVersion(u32), + #[error("Device limit reached: {current} out of {max} devices.")] + DeviceLimitReached { current: u32, max: u32 }, + #[error("HTTP reqwest error: {0}")] Http(#[from] reqwest::Error), } diff --git a/src/push_service/response.rs b/src/push_service/response.rs index 4360a4e56..ae4bc5d87 100644 --- a/src/push_service/response.rs +++ b/src/push_service/response.rs @@ -68,6 +68,27 @@ where })?; Err(ServiceError::ProofRequiredError(proof_required)) }, + StatusCode::LENGTH_REQUIRED => { + #[derive(Debug, serde::Deserialize)] + struct LinkedDeviceNumberError { + current: u32, + max: u32, + } + let error: LinkedDeviceNumberError = + response.json().await.map_err(|error| { + tracing::warn!( + %error, + "failed to decode linked device HTTP 411 status" + ); + ServiceError::UnhandledResponseCode { + http_code: StatusCode::LENGTH_REQUIRED.as_u16(), + } + })?; + Err(ServiceError::DeviceLimitReached { + current: error.current, + max: error.max, + }) + }, // XXX: fill in rest from PushServiceSocket code => { let response_text = response.text().await?;