Skip to content

Commit

Permalink
fix(make_request): don't blindly try to check the content-type
Browse files Browse the repository at this point in the history
Ensure that the response has one first

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
(cherry picked from commit 152c4d4)
  • Loading branch information
akhilnarang authored and mergify[bot] committed Jun 4, 2024
1 parent a05d9b6 commit 2fc914f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions frappe/integrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ def make_request(method, url, auth=None, headers=None, data=None, json=None, par
)
response.raise_for_status()

content_type = response.headers.get("content-type")
if content_type == "text/plain; charset=utf-8":
return parse_qs(response.text)
elif content_type.startswith("application/") and content_type.split(";")[0].endswith("json"):
return response.json()
elif response.text:
return response.text
else:
return
# Check whether the response has a content-type, before trying to check what it is
if content_type := response.headers.get("content-type"):
if content_type == "text/plain; charset=utf-8":
return parse_qs(response.text)
elif content_type.startswith("application/") and content_type.split(";")[0].endswith("json"):
return response.json()
elif response.text:
return response.text
return
except Exception as exc:
frappe.log_error()
raise exc
Expand Down

0 comments on commit 2fc914f

Please sign in to comment.