msg = $e->getMessage() ?: $this->msg; //兼容Exception类 这个类没有getStatusCode方法 if ($e instanceof HttpException) { $this->httpStatusCode = $e->getStatusCode() ?: $this->httpStatusCode; } $this->code = $e->getCode() ?: $this->code; $data = [ 'msg' => $this->msg, 'data' => [], 'code' => $this->code, ]; return json($data, $this->httpStatusCode); } }