什么会导致错误在Laravel中没有消息

时间:2016-04-14 13:37:47

标签: php laravel

所以这个问题更多地基于为什么只有错误的一部分显示错误本身(尽管如果有人也可以解决错误那么会很好)。

但是,我在Laravel中有一个日志功能,可以通过电子邮件发送错误通知并将其记录下来。 (不可否认,它可能不是最好的做法,尽管它倾向于达到其目的)。我发送错误电子邮件的代码如下所示......

异常\ Handler.php

public function report(Exception $e)
{
    \Mail::send('emails.error', ['error' => $e], function ($m) use ($e) {


        $m->from('noreply@mydomain.com', 'MMC API | Laravel Error ');

        $m->to('me@mydomain.com')
        ->cc('someoneelse@mydomain.com')
        ->subject($e->getMessage());
    });

    parent::report($e);
}

资源\视图\电子邮件\ error.blade.php

<p><strong>Message: </strong>{{ $error->getMessage() }}</p>
<p><strong>File: </strong>{{ $error->getFile() }}</p>
<p><strong>Trace: </strong>{{$error->getTraceAsString()}}</p>

但是,我刚收到并收到错误,但没有来自电子邮件getMessage()部分的消息(如下所示)......

Message: 
File: C:\api\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php
Trace: 
    #0 C:\api\vendor\laravel\framework\src\Illuminate\Routing\Router.php(823): Illuminate\Routing\RouteCollection->match(Object(Illuminate\Http\Request)) 
    #1 C:\api\vendor\laravel\framework\src\Illuminate\Routing\Router.php(691): Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request)) 
    #2 C:\api\vendor\laravel\framework\src\Illuminate\Routing\Router.php(675): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request)) 
    #3 C:\api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(246): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request)) 
    #4 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request)) 
    #5 C:\api\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(52): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
    #6 C:\api\vendor\barryvdh\laravel-cors\src\HandleCors.php(34): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
    #7 [internal function]: Barryvdh\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure)) 
    #8 C:\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array) 
    #9 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
    #10 C:\api\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
    #11 C:\api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(44): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
    #12 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure)) 
    #13 C:\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(124): call_user_func_array(Array, Array) 
    #14 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request)) 
    #15 C:\api\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
    #16 [internal function]: Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request)) 
    #17 C:\api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) 
    #18 C:\api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(132): Illuminate\Pipeline\Pipeline->then(Object(Closure)) 
    #19 C:\api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(99): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request)) 
    #20 C:\api\public\index.php(54): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request)) 
    #21 {main}

似乎Barryvdh\Cors\HandleCors-可能出现了问题,我使用它来启用跨域API,或者可能是网络爬虫试图绕过与我允许的路径不同的路径。

对于我原来的问题:是否可能在没有消息的情况下出错,我可以通过getMessage()

获取消息

奖金问题:是否可以使用我提供的有限信息来诊断路线错误?

2 个答案:

答案 0 :(得分:3)

原始问题的答案是肯定的,你可以有一个没有消息的例外。

您的奖金问题的答案是肯定的,您可以根据当前信息获得有根据的猜测。执行此操作时,这实际上会显示原始问题的答案。

从堆栈跟踪中,它显示调用的最后一个方法(来自第0行)是Illuminate\Routing\RouteCollection->match。如果您进入the code并查看此方法,则可以看到,如果没有匹配的路由,则会调用throw new NotFoundHttpException;

鉴于这是此方法显式抛出的唯一Exception,以及在没有设置消息的情况下抛出它的事实,这是一个很好的猜测,这是您的错误。

所以,基本上,有人试图去一条不存在的路线。

答案 1 :(得分:0)

我之前曾见过这种错误,但没有邮寄。但我可以告诉您,错误是由您的Route引起的,或者您尝试访问不存在的Route方法,或者您使用了错误的Route方法