Laravel – Redis error when dispatching a job

On one of the systems that I take care of, some times some jobs don’t get dispatched due to a connection problem with Redis and this ends up returning an error to the user, on our side we can ignore this error and just miss this job, I looked for how to deal with it on Google and I didn’t find anything about it.

public function sendMessage(Request $request, Model $model)
{
    // Do the necessary stuff
    
    ResolveMessageBilling::dispatch($model, $request->all());

    return response()->json([
        'message' => 'The message was succesfully sent'
    ], 200);
}

This is the error we are getting: RedisException - socket error on read socket

How to ignore the error if it occurs? A simple try/catch can resolve the issue?

public function sendMessage(Request $request, Model $model)
{
    // Do the necessary stuff

    try {
        ResolveMessageBilling::dispatch($model, $request->all());
    } catch(Exception $e) {}

    return response()->json([
        'message' => 'The message was succesfully sent'
    ], 200);
}

Leave a Comment