简体   繁体   English

改变“哎呀,看起来像是出了问题。”的消息

[英]Change “Whoops, looks like something went wrong.” message

I'm sure I'm missing something silly here. 我确定我在这里错过了一些愚蠢的东西。 I'm trying to replace the non-debug error screen that Laravel throws when there's an exception. 我正在尝试替换Laravel在出现异常时抛出的非调试错误屏幕。 It seems to be ignoring the code below (placed in start/global.php ): 它似乎忽略了下面的代码(放在start/global.php ):

App::error(function(Exception $exception, $code)
{
    Log::error($exception);
    if(!Config::get('app.debug')) {
        return Response::view('errors.exception', ['message' => $exception->getMessage()], 500);
    }
});

Why would it ignore that? 为什么会忽略这一点? And was I supposed to do something elsewhere as well? 我本来应该在其他地方做些什么吗?

Bit of clarity: 有点清晰:

I'm testing this with a QueryException ( HY000 ). 我正在使用QueryExceptionHY000 )测试它。 But surely this should not make a difference? 但这肯定不会有所作为?

Using Laravel 4.2 使用Laravel 4.2

It'd be hard to say without seeing your system, but my first guess would be there's another call to App:error made after yours that overrides what's you're trying to do in app/global.php . 没有看到你的系统就很难说,但是我的第一个猜测就是对App:error的另一个调用App:error在你的App:error之后发生的App:error会覆盖你在app/global.php尝试做的事情。

I just wrote about how Laravel sets up it's error handling recently . 我刚刚写了关于Laravel 最近如何设置它的错误处理的文章 After reading that article (or maybe skipping it and diving in), the way I'd debug this would be to hop into 阅读完那篇文章(或者跳过它并潜入)之后,我调试这个的方式就是跳进去

vendor/laravel/framework/src/Illuminate/Exception/Handler.php

and look at the definition of callCustomHandlers . 并查看callCustomHandlers的定义。 This is the method that calls any handlers setup via App:error 这是通过App:error调用任何处理程序设置的方法

protected function callCustomHandlers($exception, $fromConsole = false)
{
    foreach ($this->handlers as $handler)
    {
        //...
    }
}

Your handler will be in the $this->handlers array. 您的处理程序将位于$this->handlers数组中。 I'd add some temporary debugging code to this class (the class may be in Laravel's single combined optimized file) to determine 我将为此类添加一些临时调试代码(该类可能在Laravel的单个组合优化文件中)来确定

  1. If your handler fails the handlesException test 如果你的处理程序失败了handlesException测试

  2. If there's another handler added to the queue after your that "wins" and sends a response. 如果在“获胜”并发送响应之后有另一个处理程序添加到队列中。

It also never hurts to start with a 从一开始也不会伤害

App::error(function()
{
    exit(__FILE__);
});

and then build out your error handler until it stops being called. 然后构建你的错误处理程序,直到它被停止被调用。 That way you know what part of it Laravel's having a problem with. 那样你就知道Laravel有什么问题了。

In app/global.php there is a default error handler setup. app/global.php有一个默认的错误处理程序设置。 You will want to remove that to use yours, or just modify that one. 您将要删除它以使用您的,或只是修改那个。

Check this out for more information... http://laravel.com/docs/errors#handling-errors 查看更多信息... http://laravel.com/docs/errors#handling-errors

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 哎呀,看起来出事了。 Laravel 5.0 - Whoops, looks like something went wrong. Laravel 5.0 哎呀,看起来像出事了。 LARAVEL错误 - Whoops, looks like something went wrong. LARAVEL ERROR “哇,看起来好像出了点问题。” Laravel 4.1 - “Whoops, looks like something went wrong.” Laravel 4.1 哎呀,看起来出事了。 共享主机错误 - Whoops, looks like something went wrong. error on shared hosting 哎呀,看起来出事了。 尝试在内置服务器上运行时 Laravel 5 中的错误 - Whoops, looks like something went wrong. error in Laravel 5 when trying to run on built in server 运行Laravel 5 Server时出现问题。 “糟糕,好像出了点问题。” http://127.0.0.1:8000/ - Trouble running Laravel 5 Server. “Whoops, looks like something went wrong.” http://127.0.0.1:8000/ Laravel v5.2.38的错误报告比“糟糕,好像出了点问题”更好。 - Laravel v5.2.38 better error reporting than “Whoops, looks like something went wrong.” 使用laravel 5.4项目在浏览器上进行多次刷新时会出现错误“糟糕,好像出了点问题。” - multiple refresh on browser with laravel 5.4 project get error “Whoops, looks like something went wrong.” Laravel Form:哎呀,好像出了点问题 - Laravel Form: Whoops, looks like something went wrong routes.php和哎呀,好像出了点问题 - routes.php and whoops, looks like something went wrong
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM