修改exception
This commit is contained in:
parent
70889deb73
commit
3c3c0471e1
@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
namespace app\admin\request;
|
namespace app\admin\request;
|
||||||
|
|
||||||
use think\exception\HttpException;
|
use think\exception\HttpResponseException;
|
||||||
use think\Request;
|
use think\Request;
|
||||||
|
|
||||||
abstract class FormRequest extends Request
|
abstract class FormRequest extends Request
|
||||||
@ -20,7 +20,11 @@ abstract class FormRequest extends Request
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
if ($this->withServer($_SERVER)->isAjax(true) && $err = $this->validate()) {
|
if ($this->withServer($_SERVER)->isAjax(true) && $err = $this->validate()) {
|
||||||
throw new HttpException(0, $err);
|
throw new HttpResponseException(json([
|
||||||
|
'code' => 0,
|
||||||
|
'msg' => $err,
|
||||||
|
'wait' => 3,
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,44 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: Administrator
|
|
||||||
* Date: 2018/11/30
|
|
||||||
* Time: 17:25
|
|
||||||
*/
|
|
||||||
namespace app\exceptions;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use think\exception\HttpException;
|
|
||||||
|
|
||||||
class Handle extends \think\exception\Handle
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* rewrite render
|
|
||||||
*
|
|
||||||
* @time at 2018年11月30日
|
|
||||||
* @param Exception $e
|
|
||||||
* @return \think\Response|\think\response\Json
|
|
||||||
*/
|
|
||||||
public function render(Exception $e)
|
|
||||||
{
|
|
||||||
switch (true) {
|
|
||||||
case $e instanceof HttpException:
|
|
||||||
return $this->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,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -141,6 +141,6 @@ return [
|
|||||||
// 显示错误信息
|
// 显示错误信息
|
||||||
'show_error_msg' => false,
|
'show_error_msg' => false,
|
||||||
// 异常处理handle类 留空使用 \think\exception\Handle
|
// 异常处理handle类 留空使用 \think\exception\Handle
|
||||||
'exception_handle' => app\exceptions\Handle::class,
|
'exception_handle' => ''
|
||||||
|
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user