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

An exception is raised if req.header contains a property whose value is undefined #17

Open
mpvosseller opened this issue Jun 21, 2020 · 0 comments
Assignees
Labels

Comments

@mpvosseller
Copy link
Contributor

mpvosseller commented Jun 21, 2020

If req.header contains a property whose value is undefined then the koa2-winston logger raises an exception with a stack trace like this:

TypeError: Cannot read property 'toString' of undefined
    at $asString (eval at build (/path/node_modules/fast-json-stringify/index.js:149:20), <anonymous>:16:15)
    at $mainreqheader (eval at build (/path/node_modules/fast-json-stringify/index.js:149:20), <anonymous>:371:44)
    at $mainreq (eval at build (/path/node_modules/fast-json-stringify/index.js:149:20), <anonymous>:229:17)
    at $main (eval at build (/path/node_modules/fast-json-stringify/index.js:149:20), <anonymous>:190:17)
    at Printf.template (/path/node_modules/koa2-winston/stringify_schema.js:204:21)
    at Printf.transform (/path/node_modules/logform/printf.js:11:26)
    at Format.transform (/path/node_modules/logform/combine.js:20:24)
    at DerivedLogger._transform (/path/node_modules/winston/lib/winston/logger.js:305:29)
    at DerivedLogger.Transform._read (/path/node_modules/winston/node_modules/readable-stream/lib/_stream_transform.js:177:10)
    at DerivedLogger.Transform._write (/path/node_modules/winston/node_modules/readable-stream/lib/_stream_transform.js:164:83)
[ERROR] 14:09:39 TypeError: Cannot read property 'toString' of undefined

I ran into this because another middleware I'm using sets a header property and sometimes the value of that property is undefined. I did submit a PR to that middleware to omit the property when its value is undefined but koa2-winston should probably handle such cases without throwing an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants