Skip to content

Commit

Permalink
fix: make_request - prevents an error during response parsing if the …
Browse files Browse the repository at this point in the history
…response body is empty. (#24613)

* Update utils.py

Sometimes the returned response body is empty. This change prevents the error during frappe response parsing. For example DELETE request returns no content.

* Revert "Update utils.py"

This reverts commit edbfb69.

* fix: Avoid parsing empty responses in make_request

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
(cherry picked from commit c12b753)
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
  • Loading branch information
2 people authored and akhilnarang committed Apr 9, 2024
1 parent e16ebb7 commit d5c86a7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions frappe/integrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ def make_request(method, url, auth=None, headers=None, data=None, json=None, par

try:
s = get_request_session()
frappe.flags.integration_request = s.request(
response = frappe.flags.integration_request = s.request(
method, url, data=data, auth=auth, headers=headers, json=json, params=params
)
frappe.flags.integration_request.raise_for_status()

if frappe.flags.integration_request.headers.get("content-type") == "text/plain; charset=utf-8":
return parse_qs(frappe.flags.integration_request.text)

return frappe.flags.integration_request.json()
response.raise_for_status()

if response.headers.get("content-type") == "text/plain; charset=utf-8":
return parse_qs(response.text)
elif not response.text:
return
else:
response.json()
except Exception as exc:
frappe.log_error()
raise exc
Expand Down

0 comments on commit d5c86a7

Please sign in to comment.