| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace common\exceptions\handler;
- use common\exceptions\ResponseException;
- class AppExceptionHandler
- {
- /**
- * 异常处理
- * @desc
- *
- * @param \Throwable $throwable
- *
- * @return string
- */
- public function handle(\Throwable $throwable)
- {
- if ($throwable instanceof ResponseException) {
- return $throwable->getMessage();
- }
- // 记录日志...
- \Yii::error(json_encode([
- 'trace' => $throwable->getTraceAsString(),
- 'file' => $throwable->getFile(),
- 'line' => $throwable->getLine(),
- 'msg' => $throwable->getMessage()
- ], JSON_UNESCAPED_UNICODE));
- $msg = '系统错误';
- if (!YII_DEBUG) {
- $msg = sprintf("%s: err: %s, file: %s, line: %d", $msg, $throwable->getMessage(), $throwable->getFile(), $throwable->getLine());
- }
- return $msg;
- }
- }
|