Server-side API action gives incorrect response

Wappler Version : 2.8.4
Operating System : Mac OSX Catalina v10.15.3

I have a dynamic API URL (see screenshot below) and when the URL is invalid:

  • On client-side, the API call gives me a 404 correctly
  • On server-side, the same API call gives me a 200 incorrectly

Something is fundamentally wrong here.

An invalid URL doesn’t have to return a 404, it depends on the remote server. In your case you with an invalid URL you will get no status code, you get a timeout error probably. I see that those are not good captured in PHP, will see if we can improve that.

In the upcoming update it will be improved. Invalid URL will return an error (500 error, not a 404) instead of 200 response.

2 Likes

Thanks for this fix @patrick. Just want to understand one related thing.

So, an API action with invalid URL will return an 500 error, irrespective of whether the “Pass Errors” is checked or not?

image

Based on your previous reply in the below thread, when Pass Errors is unchecked, we get to manage the response ourselves on front-end.

Not a big deal for me, but thought might help stopping “Pass Errors” checkbox becoming convoluted.

Yes, with Pass Errors is unchecked you can handle the response yourself. You just check the status property and do your stuff depending on the status.

Thanks @patrick for the clarification.

Just for invalid URL alone, the error gets passed irrespective of whether the “Pass Errors” is checked or not. Hence, raised with you.

Otherwise, Pass Errors unchecked works just like how it use to:

bumping this so that this doesn’t fall off your radar, this requires a fix…

@patrick

I have to rethink this, the Pass Errors it to pass the errors from the remote host, so when it is returning a 404 or 500 error. It was not for errors in the action file, like when having a invalid URL. It is possible to capture these with the catch in the server action and the handle it there, I’m not sure if invalid input should be seen as API errors and should be handled as if the errors came from the API.

Thanks for explaining @patrick, understood and agree with your logic - “Pass Errors is only to pass errors from remote host”!

Yes, it passes the errors you get from the remote api host, not the errors generated in the action.

1 Like

This topic was automatically closed after 2 days. New replies are no longer allowed.