-
Notifications
You must be signed in to change notification settings - Fork 0
/
ErrorHandler.php
52 lines (47 loc) · 1.45 KB
/
ErrorHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Created by PhpStorm.
* User: david
* Date: 2017/3/24
* Time: 19:28
* Email:[email protected]
*/
namespace sheng\yii2doc;
use Yii;
use yii\web\Response;
use yii\web\HttpException;
class ErrorHandler extends \yii\web\ErrorHandler
{
/**
* Renders the exception.
* @param \Exception $exception the exception to be rendered.
*/
protected function renderException($exception)
{
// print_r($exception);die;
if (Yii::$app->has('response')) {
$response = Yii::$app->getResponse();
// reset parameters of response to avoid interference with partially created response data
// in case the error occurred while sending the response.
$response->isSent = false;
$response->stream = null;
$response->data = null;
$response->content = null;
} else {
$response = new Response();
}
$result = Yii::$app->runAction($this->errorAction);
if ($result instanceof Response) {
$response = $result;
} else {
$response->data = $result;
}
if ($exception instanceof HttpException) {
$response->setStatusCode($exception->statusCode);
} else {
Yii::$app->log->getLogger()->log($this->convertExceptionToArray($exception),\yii\log\Logger::LEVEL_ERROR);
$response->setStatusCode(500);
}
$response->send();
}
}