0

I have setup a email job like this:

dispatch(new NewUserEmail($newUser->email, $newUser->username));

And my job file looks like this:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;
use App\Mail\NewUser;
use Mail;

class NewUserEmail implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $email;
    protected $username;
    public $tries = 5;

    /**
     * Create a new job instance.
     */
    public function __construct($email, $username)
    {
        $this->email = $email;
        $this->username = $username;
    }

    /**
     * Execute the job.
     */
    public function handle()
    {
        try {
            Mail::to($this->email)->send(new NewUsedfr($this->username));
        } catch (\Exception $e) {
            Log::error('NewUserEmailJob failed NewUser');
            Log::error('NewUserEmailJob log: '.$e);
            throw new \Exception($e);
        }
    }
}

However on purpose I have misspelled the mail file NewUsedfr which should be NewUser In order to try tigger a exception.

But when I run the job I can see that the job finish in Horizon without being marked as failed. And looking in telescope I cant see any exceptions or errors in the log tab..

So I had manually look into my storage/logs folder and I saw this line:

Class 'App\Jobs\NewUsedfr' not found {"exception":"[object]

So why is my job not failing in horizon and why is not the above error being shown in telescope? Seems a bit weird that telescope doesnt show errors from the storage/logs folder

user2722667
  • 8,195
  • 14
  • 52
  • 100

1 Answers1

1

Instead of throwing a new exception, rethrow the original exception:

throw $e; 
Alexandre Danault
  • 8,602
  • 3
  • 30
  • 33