不知道算不算Yii2的bug,Yii2的错误处理。

19-07-24 14:35 字数 629 阅读 1469 已编辑

比如我有一个 ArticleController 继承自 BaseController ,在 BaseController中,我会判断文章的是否存在,比如前台给了一个错误的 articleID ,那么我在 BaseController 中会抛出异常

throw new NotFoundHttpException('文章不存在或状态异常');

我已经在配置文件中设置了 errorAction

'errorHandler' => [
    'errorAction' => 'site/error',
],

YII_DEBUG = true 的情况下,应该走我自定义的错误页面吧。可是结果却没有走。

追了下代码,发现问题应该出在这。

protected function renderException($exception)
{
    ...
    $useErrorView = $response->format === Response::FORMAT_HTML && (!YII_DEBUG || $exception instanceof UserException);

    if ($useErrorView && $this->errorAction !== null) {
            $result = Yii::$app->runAction($this->errorAction); // 在这里会直接报错
            if ($result instanceof Response) {
                    $response = $result;
            } else {
                    $response->data = $result;
            }
    }
    ...
}
0人点赞>
关注 收藏 改进 举报
0 条评论
排序方式 时间 投票
快来抢占一楼吧
请登录后发表评论
站长 @ 十七度
文章
380
粉丝
23
喜欢
191
收藏
31
排名 : 1
访问 : 128.33万
私信