I have a listener in laravel 9 that transfer posts, but I want to handle a custom error if the destination user is deleted
my listener currently implements ShouldQueue and actually in my method handle I have this
public function handle(TransferPostEvent $transferPostsEvent)
{
$toUser = $this->userService->getUserById($transferPostsEvent->toUserId);
if ($toUser->trashed()) {
$errorMessage = ('*** DESTINATION USER WAS DELETED BEFORE TRANSFER THE POST user id: ' . $toUser->id . '***');
$errorException = new Exception(message: $errorMessage);
$this->failed($transferPostsEvent, $errorException);
} else {
//transfer post...
}
}
and this is my failed method
/**
* @param TransferPostEvent $event
* @param \Throwable $exception
*/
public function failed(TransferPostEvent $event, \Throwable $exception)
{
Log::error($exception);
}
It seems fine, logs are ok, but the console shows 'Processed:Modules\Admin\Listeners\TransferPostListener' message and I would like to show 'Failed:'? is it ok to show 'Failed:' in the console for this type of error? How could I cause it manually?