-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse JSON internally when content-type=json
is missing.
#17
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17 +/- ##
============================================
- Coverage 100.00% 89.61% -10.39%
============================================
Files 2 3 +1
Lines 55 77 +22
============================================
+ Hits 55 69 +14
- Misses 0 8 +8
Continue to review full report in Codecov by Sentry.
|
return await result.json(); | ||
} catch(e) { | ||
const {url} = result; | ||
logger.error(`DataError: could not parse JSON from: "${url}"`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something that should be logged? Would it be good enough to let calling code handle the error? Maybe add the URL to it.
} | ||
|
||
try { | ||
return await result.json(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this should be open ended and always try to parse arbitrary input. One specific use case is when you get application/octet-stream
due to the server not knowing what to do (ex, on github pages with no extension). What other content types make sense to try and parse? If it's HTML or an image, better to not bother and let it fail. So maybe should refactor to something like as a special case:
if(result.headers.get('content-type') === 'application/octet-stream') {
// try the parse
} else {
// throw an unsupported content type error
}
(And consider using content-type
npm package for parsing the header string.)
No description provided.