Skip to content

Commit

Permalink
fix: only try JSON if content-type says so (#24936)
Browse files Browse the repository at this point in the history
Keep NoneType as the fallback

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
(cherry picked from commit 59ca074)
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
  • Loading branch information
akhilnarang committed Apr 9, 2024
1 parent d5c86a7 commit e3c5ec4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions frappe/integrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from urllib.parse import parse_qs

import frappe
from frappe import _
from frappe.utils import get_request_session


Expand All @@ -20,14 +19,15 @@ def make_request(method, url, auth=None, headers=None, data=None, json=None, par
response = frappe.flags.integration_request = s.request(
method, url, data=data, auth=auth, headers=headers, json=json, params=params
)
response.raise_for_status()

if response.headers.get("content-type") == "text/plain; charset=utf-8":
content_type = response.headers.get("content-type")
if content_type == "text/plain; charset=utf-8":
return parse_qs(response.text)
elif not response.text:
return
elif content_type.startswith("application/") and content_type.split(";")[0].endswith("json"):
return response.json()
elif response.text:
return response.text
else:
response.json()
return
except Exception as exc:
frappe.log_error()
raise exc
Expand Down

0 comments on commit e3c5ec4

Please sign in to comment.