[英]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?
我本来应该在其他地方做些什么吗?
I'm testing this with a QueryException
( HY000
). 我正在使用
QueryException
( HY000
)测试它。 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的单个组合优化文件中)来确定
If your handler fails the handlesException
test 如果你的处理程序失败了
handlesException
测试
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.