Skip to content

Conversation

@caruspi
Copy link
Contributor

@caruspi caruspi commented Feb 25, 2025

Description

The current implementation of the parse/1 function in Pigeon.FCM.Error does not correctly handle cases where the "details" list contains multiple elements. It only matches when only one element is in the list and has an "errorCode", causing certain errors to be mapped as :unknown_error instead of the expected values.

In our production logs, we are seeing a large number of :unknown_error entries with the following error message:

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

This should be mapped as :unregistered, but the current implementation fails to find the "errorCode" because multiple elements are in the list.

Solution

This PR refactors the parse/1 function to use a recursive approach for parsing the "details" list. It now iterates through all elements until it finds one with an "errorCode" and correctly maps it to the corresponding atom. If no "errorCode" is found, it falls back to checking the "status" field.

…ments in "details"

Refactored the `parse/1` function to use recursion for correctly handling cases where the "details" list contains multiple elements, and falling back to the "status" field when necessary.
@caruspi caruspi force-pushed the fix/fcm-error-handling branch from 7aca252 to c19f5b0 Compare February 25, 2025 16:53
@hpopp
Copy link
Member

hpopp commented May 21, 2025

Thanks for this, it'll go out in the next release. 🍻

@hpopp hpopp merged commit 3b4ae6d into codedge-llc:main May 21, 2025
2 of 6 checks passed
@caruspi
Copy link
Contributor Author

caruspi commented Jun 19, 2025

Hi @hpopp ,

This is a beneficial change that could permit us to delete some UNREGISTERED tokens from our databases.
Are there any plans to release this soon?

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants