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

Ability to act on provider errors #78

Open
JJimmyFlynn opened this issue Oct 14, 2021 · 2 comments
Open

Ability to act on provider errors #78

JJimmyFlynn opened this issue Oct 14, 2021 · 2 comments

Comments

@JJimmyFlynn
Copy link

When an error is returned from a provider, it would be great if Postie provided a way to listen for an error response so that a different course of action could be taken.

For example: we have a site where we're using Postie to calculate UPS rates. The site sadly doesn't do any real address validation and a user could end up entering a wrong address. We would then need to show an error to the user and modify a few other things if the call to fetch rates fails.

Even having access to the raw response from the provider in the instance of an error would be a great start, as the modifyRates event doesn't fire on an error response. Though any additional helpers would also be great. :)

@engram-design
Copy link
Member

My immediate thoughts are to expose a custom flash() Twig function, for you to check if there are any Postie-related errors. The idea being:

{% if craft.app.session.getFlash('postie-error') %}
...

I might also propose another event for you to hook into in your modules in the event of an error. The tricky part is that a provider can return an error for all manner of reasons, so it'd be a good idea to filter out anything you show customer-facing.

In terms of adding this to the modifyRates, I might create a new event for errors, purely because an error can happen before rates are even fetched, and the responses from providers can vary.

@JJimmyFlynn
Copy link
Author

I think both would have pretty good utility. Particularly being able to respond to an error event and take appropriate actions.

It would be nice to have access to what the error code is, but know that's pretty unlikely due to the varying APIs for the providers. But just being notified there was an error and getting access to the raw error response would be tops!

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

No branches or pull requests

2 participants