Skip to content

Commit

Permalink
Now reading the body from the response gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
Suvish Varghese Thoovamalayil committed May 21, 2017
1 parent ca956e9 commit fd3bba1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,24 @@ impl <'a> Message<'a> {
let result = client.post("https://gcm-http.googleapis.com/gcm/send")
.body(self.to_json().to_string().as_bytes())
.header(header::Authorization("key=".to_string() + api_key))
.header(header::ContentType(Mime(TopLevel::Application,SubLevel::Json,vec![(Attr::Charset, Value::Utf8)])))
.header(
header::ContentType(
Mime(
TopLevel::Application,
SubLevel::Json,
vec![(Attr::Charset, Value::Utf8)]
)
)
)
.send();

match result {
Ok(mut res) => {
let mut body = String::new();
res.read_to_string(&mut body).unwrap(); //unsafe?
Message::parse_response(res.status, &body)
match res.read_to_string(&mut body) {
Ok(_) => Message::parse_response(res.status, &body),
Err(_) => Message::parse_response(StatusCode::InternalServerError, "Server Error")
}
},
Err(_) => {
Message::parse_response(StatusCode::InternalServerError, "Server Error")
Expand Down

0 comments on commit fd3bba1

Please sign in to comment.