Skip to content

[Notifier] [Expo] Throw exception on error-response from expo api #47626

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

Merged

Conversation

sdrewergutland
Copy link
Contributor

@sdrewergutland sdrewergutland commented Sep 20, 2022

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

Throw an actual TransportExceptionin the case that an error is returned in the response from expo api.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title [Notifier][Expo-Notifier] Set messageId only if an id is returned in Expo API Response [Notifier] [Expo-Notifier] Set messageId only if an id is returned in Expo API Response Sep 20, 2022
@OskarStark OskarStark changed the title [Notifier] [Expo-Notifier] Set messageId only if an id is returned in Expo API Response [Notifier][Expo] Set messageId only if an id is returned in Expo API Response Sep 20, 2022
@OskarStark OskarStark changed the title [Notifier][Expo] Set messageId only if an id is returned in Expo API Response [Notifier][Expo] Set messageId only if an id is returned Sep 20, 2022
@fabpot
Copy link
Member

fabpot commented Sep 20, 2022

Does it mean that the current way to deal with errors is wrong? Can we fix that instead?

@sdrewergutland
Copy link
Contributor Author

Yes, I suppose that would be another option; that would make it more consistent with how other transports handle errors that are not Connection/Authorization based. So a solution in the manner of

if (false === isset($success['smsId'])) {
throw new TransportException(sprintf('Unable to send the SMS: "%s" (%s).', $success['description'], $success['code']), $response);
}

But that would cause a BC break I assume since now receiving an Exception when a device is not registered is very different behaviour. But if that is acceptable I would close this PR and open one with the correct description and implementation of the solution then.

@fabpot
Copy link
Member

fabpot commented Sep 21, 2022

But IIUC, right now, the message is not sent and you don't get any error. So, that's a bug that should be fixed.

@sdrewergutland sdrewergutland force-pushed the expo-transport-message-id-optional branch from 62966bb to c31dfd2 Compare September 22, 2022 05:04
@sdrewergutland
Copy link
Contributor Author

Alright, thanks for the feedback & PR is updated.

@sdrewergutland sdrewergutland changed the title [Notifier][Expo] Set messageId only if an id is returned [Notifier][Expo] Throw exception on error-response from expo api Sep 25, 2022
@@ -93,6 +93,11 @@ protected function doSend(MessageInterface $message): SentMessage

$success = $response->toArray(false);

$isError = 'error' === $success['data']['status'];
if ($isError) {
throw new TransportException(sprintf('Unable to post the Expo message: "%s" (%s)', $success['data']['message'], $success['data']['details']['error']), $response);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you have an example of a resulting message?
Maybe a link to the doc about this structure also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a link to the API docs in the transport;

And as for an response for an error case:

{
  "data": {
    "status": "error",
    "message": "\"ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]\" is not a registered push notification recipient",
    "details": {
      "error": "DeviceNotRegistered",
      "expoPushToken": "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]"
    }
  }
}

This can be reproduced with

curl -H "Content-Type: application/json" -X POST "https://exp.host/--/api/v2/push/send" -d '{
  "to": "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
  "title":"hello",
  "body": "world"
}'

Any other possible error like invalid auth tokens etc. would be handled by a non 200 http status. AFAIK this is the only case that is still an error but would come back as HTTP/200

Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, after my comment

@carsonbot carsonbot changed the title [Notifier][Expo] Throw exception on error-response from expo api [Notifier] [Expo] Throw exception on error-response from expo api Sep 29, 2022
@fabpot fabpot force-pushed the expo-transport-message-id-optional branch from 74dde0e to 90638ac Compare September 30, 2022 08:22
@fabpot
Copy link
Member

fabpot commented Sep 30, 2022

Thank you @sdrewergutland.

@fabpot fabpot merged commit ef3df52 into symfony:5.4 Sep 30, 2022
@sdrewergutland sdrewergutland deleted the expo-transport-message-id-optional branch September 30, 2022 08:45
This was referenced Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants