Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin/custom): fix http api as datasource wrong response check #400

Merged
merged 1 commit into from
May 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/api/bkuser_core/categories/plugins/custom/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,24 @@ def _fetch_items(self, path: str):
raise CustomAPIRequestFailed()

try:
return resp.json().get("results", [])
resp_body = resp.json()
except Exception as e:
logger.exception("failed to parse resp as json, cUrl format: %s", curl_format)
raise CustomAPIRequestFailed() from e

# results not present in response body
if "results" not in resp_body:
logger.error("no `results` in response, cUrl format: %s", curl_format)
raise CustomAPIRequestFailed("there got no `results` in response body")

results = resp_body.get("results", [])
# results not a list
if not isinstance(results, list):
logger.error("`results` in response is not a list, cUrl format: %s", curl_format)
raise CustomAPIRequestFailed("the `results` in response is not a list")

return results

def fetch_profiles(self, page_info: Optional[PageInfo] = None) -> CustomTypeList:
"""获取 profile 对象列表"""
results = self._fetch_items(path=self.paths["profile"])
Expand Down