You could customize your app's Exception Handler to normalize the error responses.
The docs outlines how to do it:
https://laravel.com/docs/8.x/errors#rendering-exceptions
You would add something like this:
$this->renderable(function (\Throwable $e, Request $request) {
if (! $request->expectsJson()) {
return null; // let Laravel handle it
}
if ($e instanceof ValidationException) {
return null; // let Laravel handle it
}
if ($e instanceof AuthenticationException) {
return null; // let Laravel handle it
}
$message = $this->isHttpException($e) ? $e->getMessage() : 'Server Error';
$statusCode = $this->isHttpException($e) ? $e->getStatusCode() : 500;
return response()->json([
'message' => $message,
'errors' => [],
], $statusCode);
});
Hope this helps.