diff --git a/CHANGELOG.md b/CHANGELOG.md index ff8fc513..7c91992b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ - Resolve APNS `:too_many_provider_token_updates` by moving token generation into `APNS.Token` ([#227](https://github.com/codedge-llc/pigeon/pull/227)). - Support HTTPoison 2.0. ([#236](https://github.com/codedge-llc/pigeon/pull/236)) -- Fix `DispatcherWorker` missing a clause for `{:stop, reason}` in the init function +- Improve handling of FCM error responses. ([#245](https://github.com/codedge-llc/pigeon/pull/245)) +- Fix `DispatcherWorker` missing a clause for `{:stop, reason}` in the init function. - `APNS.Config` keys now decode properly for PEMs generated with OpenSSL 3. ([#248](https://github.com/codedge-llc/pigeon/pull/248)) - Add `ExpiredToken` as APNS error response. ([#240](https://github.com/codedge-llc/pigeon/pull/240)) - Better handling of APNS token lifecycle between `:dev`/`:prod` environments with the same key identifier. ([#239](https://github.com/codedge-llc/pigeon/pull/239)) diff --git a/lib/pigeon/fcm/error.ex b/lib/pigeon/fcm/error.ex index 5327fc0e..b75588e2 100644 --- a/lib/pigeon/fcm/error.ex +++ b/lib/pigeon/fcm/error.ex @@ -5,6 +5,9 @@ defmodule Pigeon.FCM.Error do @doc false @spec parse(map) :: Notification.error_response() + def parse(%{"details" => [%{"errorCode" => error_code}]}), + do: parse_response(error_code) + def parse(error) do error |> Map.get("status") @@ -19,5 +22,5 @@ defmodule Pigeon.FCM.Error do defp parse_response("UNAVAILABLE"), do: :unavailable defp parse_response("INTERNAL"), do: :internal defp parse_response("THIRD_PARTY_AUTH_ERROR"), do: :third_party_auth_error - defp parse_response(_), do: :unknown_error + defp parse_response(_other), do: :unknown_error end diff --git a/lib/pigeon/fcm/notification.ex b/lib/pigeon/fcm/notification.ex index b15a3fed..24dd5f81 100644 --- a/lib/pigeon/fcm/notification.ex +++ b/lib/pigeon/fcm/notification.ex @@ -40,6 +40,7 @@ defmodule Pigeon.FCM.Notification do | :unavailable | :internal | :third_party_auth_error + | :unknown_error @typedoc ~S""" FCM notification target. Must be one of the following: