Details
Details
- Reviewers
bartek marcin - Commits
- rCOMM666c07b51945: [Tunnelbroker] implement sending FCM message
Run this method with different params and check both error statuses and if notif is delivered to physical Android device.
Diff Detail
Diff Detail
- Repository
- rCOMM Comm
- Lint
No Lint Coverage - Unit
No Test Coverage
Event Timeline
services/tunnelbroker/src/notifs/fcm/mod.rs | ||
---|---|---|
71–134 | This looks strange but I wanted to map reqwest status codes to FCM errors |
Comment Actions
Proposed an optional alternative to error handling
services/tunnelbroker/src/notifs/fcm/mod.rs | ||
---|---|---|
71–134 | Maybe sth like this? (StatusCode implements Display trait so you can use it in the error!: impl FCMError { fn from_status(status: &StatusCode, body: typeof Body) -> Self { match status { StatusCode::BAD_REQUEST => FCMError(Unavailable), StatusCode::NOT_FOUND => FCMError(Unregistered), // ... _ => FCMError(UnspecifiedError) } } } Then the above code can be match response.status() { StatusCode::OK => { debug!("Successfully sent FCM notif to {}", token); Ok(()) } error_status => { let body = response.text().await.unwrap(); error!( "Failed sending FCM notification to: {}. Status: {}. Body: {}", token, error_status, body ); let fcm_error = FCMError::from_status(error_status, body); Err(fcm_error) } | |
77 | Can we do sth like unwrap_or_default()? It's better to avoid crashes when just trying to display error body |