In Laravel 7 this code works fine. Using `renderable` method also works in laravel 8. But I'm not sure how to register it in laravel 8 after creating a `CustomException` class.

```
    public function render($request, Exception $exception)
    {
        if ($exception instanceof ValidationException) {
            if ($request->expectsJson()) {
                return response('Sorry, validation failed.', 422);
            }
        }

        return parent::render($request, $exception);
    }

```