2 Commits
v2.6.1 ... v1

Author SHA1 Message Date
JaguarJack
160e506bfe add:优雅的返回Json数据 2020-08-27 16:19:06 +08:00
JaguarJack
a859e98207 fixed:修复类型异常未捕获 2020-08-27 16:18:09 +08:00
2 changed files with 31 additions and 0 deletions

View File

@@ -56,6 +56,11 @@ class CatchExceptionHandle extends Handle
$e = new FailedException($e->getMessage(), 10005, $e); $e = new FailedException($e->getMessage(), 10005, $e);
} }
// 类型错误
if ($e instanceof \TypeError) {
$e = new FailedException($e->getMessage(), 10005, $e);
}
return parent::render($request, $e); return parent::render($request, $e);
} }

View File

@@ -0,0 +1,26 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catcher\middlewares;
use think\Middleware;
use think\Request;
class JsonResponseMiddleware extends Middleware
{
public function handle(Request $request, \Closure $next)
{
$server = $request->server();
$server['HTTP_ACCEPT'] = 'application/json';
$request->withServer($server);
return $next($request);
}
}