Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fcm): look at the errorCode instead of status when parsing FCM errors #245

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading