Ruby Server SDK: JSON parse error with fake Expo tokens

Please provide the following:

  1. SDK Version: Ruby Expo Server SDK - 0.0.7
  2. Platforms(Android/iOS/web/all): n/a

I’m implementing push notifications in our Rails app and I added some fake “ExponentPushToken[XXXX]” tokens to send along with some valid tokens. When the fake values are included, the Exponent::Push::ResponseHandler fails with a JSON parse error. I debugged it by injecting my own ResponseHandler and I found that the response code is 200, but the body of the response is gzipped. When I unzip the body, I get the payload I would expect, stating that one of the tokens is an unregistered device.

If my request contains all valid tokens, it works as expected and is able to parse the response body as JSON.

Workaround
Implement my own ResponseHandler that checks the response Content-Type to determine if it should gzip decompress before parsing as JSON.

Expected behavior
The response should be in a JSON format

Response after decompressing the response body:

{"data":[
  {"status":"ok","id":"..."},
  {"status":"ok","id":"..."},
  {
    "status":"error",
    "message":"\"ExponentPushToken[fake-token]\" is not a registered push notification recipient",
    "details":{"error":"DeviceNotRegistered"
  }
}]}

Full error:

#<JSON::ParserError: 767: unexpected token at ''>
"/usr/local/lib/ruby/2.6.0/json/common.rb:156:in `parse'"
"/usr/local/bundle/gems/exponent-server-sdk-0.0.7/lib/exponent-server-sdk.rb:68:in `parse_json'"
"/usr/local/bundle/gems/exponent-server-sdk-0.0.7/lib/exponent-server-sdk.rb:59:in `handle'"
"/usr/local/bundle/gems/exponent-server-sdk-0.0.7/lib/exponent-server-sdk.rb:20:in `publish'"
"/app/app/workers/notification_push_worker.rb:20:in `block in perform'"
"/app/app/workers/notification_push_worker.rb:14:in `each_slice'"
"/app/app/workers/notification_push_worker.rb:14:in `perform'"
"/usr/local/bundle/gems/sidekiq-5.2.2/lib/sidekiq/processor.rb:185:in `execute_job'"

Hey @bret,

The Ruby server is maintained by the community rather than by us as we only officially support the node-sdk. The best approach to get the problem resolved would reaching out to the maintainers for the ruby library.

Cheers,
Adam

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.