Iam using Redis as cache in Laravel.
But I cannot catch Exception when laravel cannot connect to Redis (redis stopped, ...). I want catch this exception to reponse to client by JSON.
How can I do it ?
You can use render() function of App\Exceptions\Handler class as:
public function render($request, Exception $exception)
{
if ($exception instanceof SomeRedisException) {
return response()->json('Redis Error',500);
}
return parent::render($request, $exception);
}
Docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With