Skip to content

Commit

Permalink
fix: look at the errorCode instead of status when parsing FCM errors (#…
Browse files Browse the repository at this point in the history
…245)

This makes it so that an unregistered error, which has the status "NOT_FOUND", is appropriately handled.

Co-authored-by: Henry Popp <hpopp@users.noreply.github.com>
  • Loading branch information
mdlkxzmcp and hpopp committed Jan 17, 2024
1 parent 543d19a commit e8ec490
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 4 additions & 1 deletion lib/pigeon/fcm/error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
1 change: 1 addition & 0 deletions lib/pigeon/fcm/notification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e8ec490

Please sign in to comment.