minaremonshaker's avatar

Returning Internal Server Errors as JSON in a Laravel API

Hi,
I’m building an API, but I’m facing an issue where internal server errors are always returned as an HTML view instead of a JSON response. What options do I have to make these errors return as JSON?

For example, in Postman, if I set the Accept header to application/json, the exception is returned as JSON — that’s one approach I’ve tried. I also attempted using a middleware, but I’m still looking for a better or more reliable solution. Can anyone help?

0 likes
2 replies

Please or to participate in this conversation.