working on a somewhat complex job in Laravel but hitting something I can't get my head around.
We are getting 2 errors logged (using Flare for our logging) but we only want to have 1 error – it seems to log once for the exception thrown and another for the failed method.
Because of the complexities of the job, we've broken up the actions into their own methods.
It feels odd to not use try catches around the various bits of code and the way the code runs we throw an exception to fail the job if it hits any issues.
We like using the failed method though as it's nice to not repeat the generic error message.
Is there any way we can still throw and exception and use the failed method but not have two errors logged?
The below is pseudo but explains the issue:
class ProcessCancellation implements ShouldQueue
{
public function handle()
{
// various other methods
self::emailCustomer();
}
private function emailCustomer()
{
try {
// email customer
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
public function failed(Throwable $e)
{
Log::error('An error occurred: ' . print_r($e->getMessage(), true));
}
}