|
@@ -13,25 +13,30 @@ class ExceptionHandle extends Handle
|
|
|
|
|
|
public function render(Exception $e)
|
|
|
{
|
|
|
- // 在生产环境下返回code信息
|
|
|
- if (!\think\Config::get('app_debug')) {
|
|
|
- $statuscode = $code = 500;
|
|
|
- $msg = 'An error occurred';
|
|
|
- // 验证异常
|
|
|
- if ($e instanceof \think\exception\ValidateException) {
|
|
|
- $code = 0;
|
|
|
- $statuscode = 200;
|
|
|
- $msg = $e->getError();
|
|
|
- }
|
|
|
- // Http异常
|
|
|
- if ($e instanceof \think\exception\HttpException) {
|
|
|
- $statuscode = $code = $e->getStatusCode();
|
|
|
- }
|
|
|
- return json(['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => null], $statuscode);
|
|
|
+ //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();
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = ['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => null];
|
|
|
+
|
|
|
+ //记录app异常返回结果
|
|
|
+ if(defined('API_REQUEST_ID')) { //记录app正常返回结果
|
|
|
+ db('api_request_log')->where('id',API_REQUEST_ID)->update(['result'=>json_encode($result)]);
|
|
|
}
|
|
|
|
|
|
- //其它此交由系统处理
|
|
|
- return parent::render($e);
|
|
|
+ return json($result, $statuscode);
|
|
|
}
|
|
|
|
|
|
}
|