在页面 App\Exceptions 下的 Handler 方法中修改
public function render($request, Exception $exception)
{
if (getenv('APP_DEBUG') === 'true') {
$data = [
'code' => $exception->getCode(),
'msg' => $exception->getMessage()
];
return response()->json($data);
// return parent::render($request, $exception);
}
if ($exception instanceof ApiException) {
return $exception->render($request);
}
$data = [
'code' => $exception->getCode(),
'msg' => $exception->getMessage()
];
return response()->json($data);
}