|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace app\api\library;
|
|
|
|
|
|
+use app\service\company_wechat\Webhook;
|
|
|
use app\UserException;
|
|
|
use Exception;
|
|
|
use think\db\exception\DataNotFoundException;
|
|
@@ -20,30 +21,32 @@ class ExceptionHandle extends Handle
|
|
|
];
|
|
|
public function render(Exception $e)
|
|
|
{
|
|
|
+ $statuscode = $code = 0;
|
|
|
+ $msg = '服务器错误';
|
|
|
+ // 验证异常
|
|
|
+ if ($e instanceof \think\exception\ValidateException) {
|
|
|
+ $code = 0;
|
|
|
+ $statuscode = 200;
|
|
|
+ $msg = $e->getError();
|
|
|
+ }
|
|
|
+ // Http异常
|
|
|
+ elseif ($e instanceof \think\exception\HttpException) {
|
|
|
+ $statuscode = $code = $e->getStatusCode();
|
|
|
+ }
|
|
|
+ elseif ($e instanceof UserException) {
|
|
|
+ $code = 0;
|
|
|
+ $msg = $e->getMessage();
|
|
|
+ $statuscode = 200;
|
|
|
+ }
|
|
|
+ elseif ($e instanceof ModelNotFoundException) {
|
|
|
+ $msg = '查找的数据不存在';
|
|
|
+ }else{
|
|
|
+ Webhook::push($e);
|
|
|
+ }
|
|
|
// 在生产环境下返回code信息
|
|
|
//if (!\think\Config::get('app_debug')) {
|
|
|
if(request()->isAjax() || strpos(request()->header('Accept'),'/json')!==false) {
|
|
|
- $statuscode = $code = 0;
|
|
|
//$msg = 'An error occurred';
|
|
|
- $msg = '服务器错误';
|
|
|
- // 验证异常
|
|
|
- if ($e instanceof \think\exception\ValidateException) {
|
|
|
- $code = 0;
|
|
|
- $statuscode = 200;
|
|
|
- $msg = $e->getError();
|
|
|
- }
|
|
|
- // Http异常
|
|
|
- if ($e instanceof \think\exception\HttpException) {
|
|
|
- $statuscode = $code = $e->getStatusCode();
|
|
|
- }
|
|
|
- if ($e instanceof UserException) {
|
|
|
- $code = 0;
|
|
|
- $msg = $e->getMessage();
|
|
|
- $statuscode = 200;
|
|
|
- }
|
|
|
- if ($e instanceof ModelNotFoundException) {
|
|
|
- $msg = '查找的数据不存在';
|
|
|
- }
|
|
|
return json(['code' => $code, 'msg' => $msg, 'time' => time(), 'data' => null], $statuscode);
|
|
|
}
|
|
|
//}
|