wetcat-studios / fortie

Laravel 5 package for Fortnox API
Apache License 2.0
19 stars 20 forks source link

Handle "Too many requests" error #47

Open jongotlin opened 5 years ago

jongotlin commented 5 years ago

Today we assume all responses are in json format but html can also be returned which causes an ErrorException (Trying to get property 'ErrorInformation' of non-object.)

<html> <head><title>429 Too Many Requests</title></head> <body bgcolor="white"> <center><h1>429 Too Many Requests</h1></center> <hr><center>nginx</center> </body> </html>

Related code https://github.com/wetcat-studios/fortie/blob/master/src/Providers/ProviderBase.php#L210-L229

agoransson commented 5 years ago

Apologies about the late reply, I've been swamped (and still am).

agoransson commented 5 years ago

I believe I've read an email update from Fortnox about new API limits. Perhaps a throttle would be a good idea? If the response is a standard HTML formatted 429... perhaps it's really an error on Fortnox' side of things?

agoransson commented 5 years ago

Related information https://developer.fortnox.se/documentation/general/regarding-fortnox-api-rate-limits/

jongotlin commented 5 years ago

Even if a throttle is implemented a 5xx-error can be returned and we cannot take for granted the response is valid json.

agoransson commented 4 years ago

So, I see two options then.

Either checking the response code (assuming that Fortnox always returns the same type on the different response-codes). Or, which should be done anyway, adding a fail-safe parsing which terminates gracefully on errors. (try-catch)

agoransson commented 4 years ago

And of course, parsing error messages (based on provided format) to display to the client.