401, 'msg' => $exception->getMessage()], JSON_UNESCAPED_UNICODE); return new Response(401, ['Content-Type' => 'application/json'], $json); } elseif ($exception instanceof BusinessException) { return json(['code' => 0, 'msg' => $exception->getMessage(), 'show' => 1]); } elseif ($exception instanceof \Exception) { $isDebug = config('app.debug'); $error = [ 'show' => 1, 'code' => $isDebug ? $exception->getCode() : 0, 'msg' => $isDebug ? $exception->getMessage() : '服务器内部错误', ]; if ($isDebug) { $error['file'] = $exception->getFile(); $error['line'] = $exception->getLine(); } $json = json_encode($error, JSON_UNESCAPED_UNICODE); return new Response(200, ['Content-Type' => 'application/json'], $json); } // 非json请求则返回一个页面 return new Response(200, [], 'msg:' . $exception->getMessage() . '。line:' . $exception->getLine() . '。file:' . $exception->getFile()); } }