diff --git a/application/admin/request/FormRequest.php b/application/admin/request/FormRequest.php index 44bedf0..3a839d1 100644 --- a/application/admin/request/FormRequest.php +++ b/application/admin/request/FormRequest.php @@ -6,6 +6,7 @@ */ namespace app\admin\request; +use think\exception\HttpException; use think\Request; abstract class FormRequest extends Request @@ -19,20 +20,7 @@ abstract class FormRequest extends Request parent::__construct(); if ($this->withServer($_SERVER)->isAjax(true) && $err = $this->validate()) { - exit($this->error($err)); + throw new HttpException(0, $err); } } - - protected function error($msg = '', $url = null, $data = '', $wait = 3, array $header = []) - { - - return json([ - 'code' => 0, - 'msg' => $msg, - 'data' => $data, - 'url' => $url, - 'wait' => $wait, - ])->send(); - } - } \ No newline at end of file diff --git a/application/exceptions/Handle.php b/application/exceptions/Handle.php new file mode 100644 index 0000000..25aadd5 --- /dev/null +++ b/application/exceptions/Handle.php @@ -0,0 +1,44 @@ +error($e->getMessage()); + break; + default: + return $this->convertExceptionToResponse($e); + break; + } + } + + protected function error($msg = '', $url = null, $data = '', $wait = 3, array $header = []) + { + return json([ + 'code' => 0, + 'msg' => $msg, + 'data' => $data, + 'url' => $url, + 'wait' => $wait, + ]); + } +} \ No newline at end of file diff --git a/config/app.php b/config/app.php index cdd7da1..4a26e13 100644 --- a/config/app.php +++ b/config/app.php @@ -141,6 +141,6 @@ return [ // 显示错误信息 'show_error_msg' => false, // 异常处理handle类 留空使用 \think\exception\Handle - 'exception_handle' => '', + 'exception_handle' => app\exceptions\Handle::class, ];