| Conditions | 6 |
| Paths | 32 |
| Total Lines | 34 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public function actionError() |
||
| 23 | { |
||
| 24 | if (($exception = \Yii::$app->getErrorHandler()->exception) === null) { |
||
| 25 | // action has been invoked not from error handler, but by direct route, so we display '404 Not Found' |
||
| 26 | $exception = new NotFoundHttpException('Endpoint not found.'); |
||
| 27 | } |
||
| 28 | |||
| 29 | if ($exception instanceof HttpException) { |
||
| 30 | $code = $exception->statusCode; |
||
| 31 | } else { |
||
| 32 | $code = $exception->getCode(); |
||
| 33 | } |
||
| 34 | |||
| 35 | if ($exception instanceof Exception) { |
||
| 36 | $name = $exception->getName(); |
||
| 37 | } else { |
||
| 38 | $name = 'Error'; |
||
| 39 | } |
||
| 40 | if ($code) { |
||
| 41 | $name .= " (#$code)"; |
||
| 42 | } |
||
| 43 | |||
| 44 | if ($exception instanceof UserException) { |
||
| 45 | $message = $exception->getMessage(); |
||
| 46 | } else { |
||
| 47 | $message = 'An internal server error occurred.'; |
||
| 48 | } |
||
| 49 | |||
| 50 | \Yii::$app->response->format = Response::FORMAT_JSON; |
||
| 51 | |||
| 52 | return [ |
||
| 53 | 'name' => $name, |
||
| 54 | 'message' => $message, |
||
| 55 | 'exception' => $exception, |
||
| 56 | ]; |
||
| 59 |