Skip to content

Commit

Permalink
Allow debugging the passing through JSON data.
Browse files Browse the repository at this point in the history
  • Loading branch information
rubdos committed Jun 20, 2020
1 parent 4436476 commit 235fe16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions libsignal-service-actix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ libsignal-protocol = { git = "https://github.com/Michael-F-Bryan/libsignal-proto

awc = { version = "2.0.0-alpha.2", features=["rustls"] }
actix-rt = "1.1"
serde_json = "1.0"
rustls = "0.17"
url = "2.1"
serde = "1.0"
Expand Down
30 changes: 25 additions & 5 deletions libsignal-service-actix/src/push_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,32 @@ impl PushService for AwcPushService {

ServiceError::from_status(response.status())?;

response
.json()
.await
.map_err(|e| ServiceError::JsonDecodeError {
reason: e.to_string(),
// In order to debug the output, we collect the whole response.
// The actix-web api is meant to used as a streaming deserializer,
// so we have this little awkward switch.
//
// This is also the reason we depend directly on serde_json, however
// actix already imports that anyway.
if log::log_enabled!(log::Level::Debug) {
let text = response.body().await.map_err(|e| {
ServiceError::JsonDecodeError {
reason: e.to_string(),
}
})?;
log::debug!("GET response: {:?}", String::from_utf8_lossy(&text));
serde_json::from_slice(&text).map_err(|e| {
ServiceError::JsonDecodeError {
reason: e.to_string(),
}
})
} else {
response
.json()
.await
.map_err(|e| ServiceError::JsonDecodeError {
reason: e.to_string(),
})
}
}
}

Expand Down

0 comments on commit 235fe16

Please sign in to comment.