Skip to content

Commit

Permalink
Catch HTTP 411 link error
Browse files Browse the repository at this point in the history
  • Loading branch information
rubdos committed Dec 18, 2024
1 parent e6affcc commit f297505
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/push_service/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
21 changes: 21 additions & 0 deletions src/push_service/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down

0 comments on commit f297505

Please sign in to comment.