API calls - one of them returns error

I have three calls made to external API from within PHP script. I get 200 code when PHP returns but when I pass this data to my JS code one of those API calls returned no data due to error. Would I handle this error within my JS code or PHP? this is what I get when I output returned data within JS console.

image

You must not only check the response code of the request you also need to check the returned data as the request can be successful but the API does fail in other reasons. As zou can see there is a 40x status in the return data so there has been a failure.

make sense. On the JS side I check for the returned data objects and I look for whether object has error property. would this work to complete check on JS side?

I would not recommend to forward the error to the client. All errors coming to the browser are good food for hackers ….

but i don’t really receive error. i always receive data back in the form of JSON

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.