Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
防止向错误报告发送Laravel Artisan异常_Laravel_Exception Handling_Laravel 5.2 - Fatal编程技术网

防止向错误报告发送Laravel Artisan异常

防止向错误报告发送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

我有一个Laravel应用程序,它将异常发送到服务器

以下是异常处理程序的代码:

<?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);
}