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

refactor: Rename variable json to body to avoid using built-in package name #38

Merged
merged 1 commit into from
Sep 29, 2024
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
32 changes: 16 additions & 16 deletions cozepy/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,38 +125,38 @@

def _parse_requests_code_msg(self, response: Response, data_field: str = "data") -> Tuple[Optional[int], str, Any]:
try:
json = response.json()
body = response.json()
except Exception as e: # noqa: E722
raise CozeAPIError(
response.status_code,
response.text,
response.headers.get("x-tt-logid"),
) from e

if "code" in json and "msg" in json and int(json["code"]) > 0:
return int(json["code"]), json["msg"], json.get(data_field) or None
if "error_message" in json and json["error_message"] != "":
return None, json["error_message"], None
if data_field in json:
if "first_id" in json:
if "code" in body and "msg" in body and int(body["code"]) > 0:
return int(body["code"]), body["msg"], body.get(data_field)

Check warning on line 137 in cozepy/request.py

View check run for this annotation

Codecov / codecov/patch

cozepy/request.py#L137

Added line #L137 was not covered by tests
if "error_message" in body and body["error_message"] != "":
return None, body["error_message"], None

Check warning on line 139 in cozepy/request.py

View check run for this annotation

Codecov / codecov/patch

cozepy/request.py#L139

Added line #L139 was not covered by tests
if data_field in body:
if "first_id" in body:
return (
0,
"",
{
"first_id": json["first_id"],
"has_more": json["has_more"],
"last_id": json["last_id"],
"items": json["data"],
"first_id": body["first_id"],
"has_more": body["has_more"],
"last_id": body["last_id"],
"items": body["data"],
},
)
if "debug_url" in json:
if "debug_url" in body:
return (
0,
"",
{
"data": json[data_field],
"debug_url": json["debug_url"],
"data": body[data_field],
"debug_url": body["debug_url"],
},
)
return 0, "", json[data_field]
return 0, "", json
return 0, "", body[data_field]
return 0, "", body
Loading