Skip to content

Commit 07913cf

Browse files
committed
Check content_type match instead of trapping failed parse
1 parent 9f452e5 commit 07913cf

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/pyld/documentloader/requests.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ def loader(url, options={}, link_follow_count=0):
6969
'documentUrl': response.url,
7070
'document': None
7171
}
72-
try:
72+
# Try loading the JSON if the content_type matches
73+
# A failure here means the response body is not valid json
74+
if re.match(r'^application\/(\w*\+)?json$', content_type):
7375
doc['document'] = response.json()
74-
except JSONDecodeError as e:
75-
# document body is not parseable, continue to check link headers
76-
pass
7776
# if content_type in headers['Accept']:
7877
# doc['document'] = response.json()
7978
link_header = response.headers.get('link')

0 commit comments

Comments
 (0)