I'm trying to make an application using Laravel and ReactJS, and I'm wondering what's the best way to go about creating error responses? I want all errors to return in a similar json response so that I can handle them all the same on the front end.
Right now I have a login api route, and it gives a validation error. I know how to override the default response, but I want to know what's the best way to override all responses that generate errors. That way i could send it in a format similar to the following:
That's really similar to how I want to structure my api responses. What I'm looking for is a way to catch all errors and format the api responses the same way so it's easier to consume.