laravel 更改“哎呀,好像出了点问题。” 信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25648538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change "Whoops, looks like something went wrong." message
提问by Mike Rockétt
I'm sure I'm missing something silly here. I'm trying to replace the non-debugerror screen that Laravel throws when there's an exception. It seems to be ignoring the code below (placed in start/global.php
):
我确定我在这里遗漏了一些愚蠢的东西。我正在尝试替换Laravel 在出现异常时抛出的非调试错误屏幕。它似乎忽略了下面的代码(放在 中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
). But surely this should not make a difference?
我正在用QueryException
( HY000
)测试这个。但这肯定不会有所作为吗?
Using Laravel 4.2
使用 Laravel 4.2
回答by Alan Storm
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/global.php
.
I just wrote about how Laravel sets up it's error handling recently. After reading that article (or maybe skipping it and diving in), the way I'd debug this would be to hop into
我刚刚写了 Laravel 如何设置它最近的错误处理。在阅读那篇文章(或者可能跳过它并深入研究)之后,我调试它的方式是跳入
vendor/laravel/framework/src/Illuminate/Exception/Handler.php
and look at the definition of callCustomHandlers
. This is the method that calls any handlers setup via App:error
并查看 的定义callCustomHandlers
。这是调用任何处理程序设置的方法App:error
protected function callCustomHandlers($exception, $fromConsole = false)
{
foreach ($this->handlers as $handler)
{
//...
}
}
Your handler will be in the $this->handlers
array. I'd add some temporary debugging code to this class (the class may be in Laravel's single combined optimized file) to determine
您的处理程序将在$this->handlers
数组中。我会向此类添加一些临时调试代码(该类可能位于 Laravel 的单个组合优化文件中)以确定
If your handler fails the
handlesException
testIf there's another handler added to the queue after your that "wins" and sends a response.
如果您的处理程序未通过
handlesException
测试如果在您“获胜”并发送响应之后将另一个处理程序添加到队列中。
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 的哪一部分有问题。
回答by user1669496
In app/global.php
there is a default error handler setup. You will want to remove that to use yours, or just modify that one.
其中app/global.php
有一个默认的错误处理程序设置。你会想要删除它以使用你的,或者只是修改那个。
Check this out for more information... http://laravel.com/docs/errors#handling-errors