| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 | 
							- <?php
 
- namespace app\api\library;
 
- use Exception;
 
- use think\exception\Handle;
 
- use app\utils\LogUtil;
 
- /**
 
-  * 自定义API模块的错误显示
 
-  */
 
- class ExceptionHandle extends Handle
 
- {
 
-     public function render(Exception $e)
 
-     {
 
-         return parent::render($e);
 
-         $statuscode = $code = 500;
 
-         $msg = $e->getMessage();
 
-         // 验证异常
 
-         if ($e instanceof \think\exception\ValidateException) {
 
-             $code = 0;
 
-             $statuscode = 200;
 
-             $msg = $e->getError();
 
-         }
 
-         // Http异常
 
-         if ($e instanceof \think\exception\HttpException) {
 
-             $statuscode = $code = $e->getStatusCode();
 
-             $msg = $e->getMessage();
 
-         }
 
-         $msg = '网络开小差了';
 
-         $result = ['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => null];
 
-         if (defined('API_REQUEST_LOG_TYPE') && defined('API_REQUEST_LOG_TYPE') == 1){
 
-             LogUtil::error('result','Api-Middleware-Log','request_log',$result);
 
-             LogUtil::error('ExceptionMsg','Api-Middleware-Log','request_log',$e->getMessage());
 
-             LogUtil::error('Exception','Api-Middleware-Log','request_log',$e);
 
-         }else{
 
-             //记录app异常返回结果
 
-             if(defined('API_REQUEST_ID')) { //记录app正常返回结果
 
-                 db('api_request_log')->where('id',API_REQUEST_ID)->update(['result'=>json_encode($result)]);
 
-             }
 
-         }
 
-         return json($result, $statuscode);
 
-     }
 
- }
 
 
  |