Level 30
Is it exactly what you're asking? https://laravel.com/docs/12.x/errors#rendering-exceptions-as-json
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?
Is it exactly what you're asking? https://laravel.com/docs/12.x/errors#rendering-exceptions-as-json
Please or to participate in this conversation.