codedge-llc / pigeon

iOS and Android push notifications for Elixir
https://hex.pm/packages/pigeon
MIT License
639 stars 143 forks source link

fix(fcm): ensure unregistered tokens correctly return `:unregistered` #221

Closed cjbell closed 2 weeks ago

cjbell commented 2 years ago

Currently an unregistered token in FCM will return an unknown_error response, which is incorrect. This PR correctly returns an unregistered atom for this case.

The error coming back from FCM is:

{
  code: 404, 
  details: [
    {
      @type: type.googleapis.com/google.firebase.fcm.v1.FcmError, 
      errorCode: UNREGISTERED
    }
  ], 
  message: Requested entity was not found., 
  status: NOT_FOUND
}
stefanchrobot commented 2 years ago

Maybe it would be better to actually look at the error code? Here's the decoded response body for an unregistered token:

%{
  "error" => %{
    "code" => 404,
    "details" => [
      %{
        "@type" => "type.googleapis.com/google.firebase.fcm.v1.FcmError",
        "errorCode" => "UNREGISTERED"
      }
    ],
    "message" => "Requested entity was not found.",
    "status" => "NOT_FOUND"
  }
}