File: /var/www/ipsremont-demo/app/Exceptions/Handler.php
<?php
namespace App\Exceptions;
use App\Jobs\ErrorReportJob;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* @param Throwable $exception
*
* @return void
*
* @throws Throwable
*/
public function report(Throwable $exception)
{
$skip = $exception instanceof ErrorReportException;
$skip = $skip || $exception instanceof AuthenticationException;
$skip = $skip || $exception instanceof NotFoundHttpException;
$skip = $skip || $exception instanceof ValidationException;
$skip = $skip || $exception instanceof TokenMismatchException;
$skip = $skip || $exception instanceof ModelNotFoundException;
if (!$skip) {
$trace = $exception->getTrace();
$logData = [];
foreach ($trace as $traceItem) {
$line = '';
if (!empty($traceItem['file'])) {
$line .= $traceItem['file'];
}
if (!empty($traceItem['line'])) {
$line .= ':' . $traceItem['line'];
}
if (!empty($traceItem['class'])) {
$line .= ' Class -> ' . $traceItem['class'];
}
$logData[] = $line;
}
$log = get_class($exception) . ' ' . $exception->getMessage();
Log::channel('exception')->error($log, $logData);
dispatch(new ErrorReportJob($log . PHP_EOL . join(PHP_EOL, $logData)));
}
parent::report($exception);
}
}