getError(); $code = -422; } // 请求异常 if($e instanceof HttpException && request()->isAjax()) { $msg = $e->getMessage(); $code = $e->getStatusCode(); } if(!isset($code)) { $code = -500; } if(empty($msg)) { if(method_exists($e, 'getMessage')) { $msg = $e->getMessage(); } else { $msg = '服务器错误'; } } // 结束并设置响应头 header('Content-Type: application/json; charset=utf-8'); exit(json_encode(DataReturn($msg, $code))); } // 其他错误交给系统处理 return parent::render($request, $e); } } ?>