Skip to content
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

response header content-type might be undefined #49

Closed
ozomer opened this issue Jan 1, 2015 · 1 comment
Closed

response header content-type might be undefined #49

ozomer opened this issue Jan 1, 2015 · 1 comment

Comments

@ozomer
Copy link

ozomer commented Jan 1, 2015

https://github.com/bithavoc/express-winston/blob/master/index.js#L201

res._headers['content-type'].indexOf('json') >= 0 ? JSON.parse(chunk) : chunk

res._headers['content-type'] might be undefined. indexOf throws an error.
The code should be replaced with:

(res._headers['content-type'] || '').indexOf('json') >= 0 ? JSON.parse(chunk) : chunk

Or in order to catch content-types that contain json\jsonp but not lalalajsonlalala:

/(\W|^)jsonp?(\W|$)/i.test(res._headers['content-type'] || '') ? JSON.parse(chunk) : chunk

Also, consider changing res._headers[...] with res.get(...).
Furthermore, In my opinion there is no need to wrap the JSON.parse with try-catch because I don't see a reason to use a json content-type and not returning a json object in the body...

@ozomer
Copy link
Author

ozomer commented Jan 1, 2015

Just noticed #41

@ozomer ozomer closed this as completed Jan 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant