1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php
- namespace app\api\exception;
- use Exception;
- use think\exception\Handle;
- use think\exception\HttpException;
- use think\Log;
- use think\Request;
- class ExceptionHandler extends Handle
- {
- public function render(Exception $e)
- {
-
- if (\think\App::$debug) {
- return parent::render($e);
- } else {
- if ($e instanceof HttpException) {
- if ($e->getStatusCode() == 404) {
- return json(["code" => 0, "msg" => "404 not found", "time" => time()]);
- }
- Log::error($e->getStatusCode() . " error, " . $e->getMessage());
- Log::error('请求数据 ' . var_export(Request::instance()->param(), true));
- } else {
- Log::error("未知错误 " . $e->getMessage());
- Log::error("请求数据 " . var_export(Request::instance()->param(), true));
- Log::error($e->getTraceAsString());
- return json(["code" => 0, "msg" => "未知错误", "time" => time()]);
- }
- }
- }
- }
|