fix(make_request): don't blindly try to check the content-type

Ensure that the response has one first

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang 2024-06-03 18:28:22 +05:30
parent 35a02b8d0a
commit 152c4d4b91
No known key found for this signature in database
GPG key ID: 9DCC61E211BF645F

View file

@ -21,15 +21,15 @@ def make_request(method: str, url: str, auth=None, headers=None, data=None, json
)
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:
if frappe.flags.integration_request_doc:
frappe.flags.integration_request_doc.log_error()