expectsJson()) { return json(['code' => 0, 'msg' => $exception->getMessage(),'show'=>1]); } return response($exception->getMessage()); } elseif ($exception instanceof \Error || $exception instanceof \ErrorException) { $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(); } return response(json_encode($error, JSON_UNESCAPED_UNICODE)); } // 非json请求则返回一个页面 return new Response(200, [], 'msg:'.$exception->getMessage().'。line:'.$exception->getLine().'。file:'.$exception->getFile()); } }