I´m trying to get all exceptions as jsons instead of the HTML that Laravel normally returns, but i cant get it to work in Laravel 8.
I found someone who did it in Laravel 5 with the following code in /app/Exceptions/handler.php
public function render($request, Exception $exception)
{
return response(['error'=>$exception->getMessage()], $exception->getCode() ?: 400);
}
I found this thread where they explain how to get a custom exception to return as a json, but i cant get it to work for all exceptions.
I tried doing something like this:
public function register()
{
$this->renderable(function (Exception $e, $request) {
return response()->json('errors.custom', [], 500);
});
}
The exception that I'm testing it with is Route [login] not defined. but it still returns the HTML
