防止向错误报告发送Laravel Artisan异常
我有一个Laravel应用程序,它将异常发送到服务器 以下是异常处理程序的代码:防止向错误报告发送Laravel Artisan异常,laravel,exception-handling,laravel-5.2,Laravel,Exception Handling,Laravel 5.2,我有一个Laravel应用程序,它将异常发送到服务器 以下是异常处理程序的代码: <?php namespace App\Exceptions; use Exception; use Illuminate\Session\TokenMismatchException; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Database\Eloquent\ModelNotFoundException; us
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Illuminate\Foundation\Validation\ValidationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Airbrake\Notifier;
class Handler extends ExceptionHandler
{
protected $dontReport = [
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
ValidationException::class,
TokenMismatchException::class,
];
public function report(Exception $e)
{
if ($this->shouldReport($e)) {
$options = [
'environment' => app()->environment(),
'host' => config('airbrake.server'),
'projectId' => config('airbrake.api_key'),
'projectKey' => config('airbrake.api_key'),
'rootDirectory' => base_path(),
'secure' => TRUE,
'url' => request()->fullUrl(),
];
$notifier = new Notifier($options);
$notifier->notify($e);
}
return parent::report($e);
}
public function render($request, Exception $e)
{
// Replace `ModelNotFound` with 404.
if ($e instanceof ModelNotFoundException) {
$message = 'Page not found';
if (config('app.debug')) {
$message = $e->getMessage();
}
$e = new NotFoundHttpException($message, $e);
}
$response = parent::render($request, $e);
return $response;
}
}
实际运行artisan
命令的Illumb\Foundation\Console\Kernel
类有一个函数reportException
,该函数调用ExceptionHandler
的报告方法
我在我的内核
类中添加了该方法的重写,该类检查STDIN是否为交互式终端并禁用错误报告:
protected function reportException(Exception $e)
{
// Disable exception reporting if run from the console.
if (function_exists('posix_isatty') && @posix_isatty(STDIN)) {
echo "Not sending exception report";
return;
}
parent::reportException($e);
}
实际运行artisan
命令的Illumb\Foundation\Console\Kernel
类有一个函数reportException
,该函数调用ExceptionHandler
的报告
方法
我在我的内核
类中添加了该方法的重写,该类检查STDIN是否为交互式终端并禁用错误报告:
protected function reportException(Exception $e)
{
// Disable exception reporting if run from the console.
if (function_exists('posix_isatty') && @posix_isatty(STDIN)) {
echo "Not sending exception report";
return;
}
parent::reportException($e);
}