Uh oh!
There was an error while loading. Please reload this page.
Suppress error handler stack traces in production#564 - #1502
Suppress error handler stack traces in production#564#1502digitalsadhu wants to merge 12 commits into
Conversation
slnode
commented
Jul 5, 2015
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
bajtos
commented
Jul 7, 2015
Hi @digitalsadhu, thank you for the pull request. I would prefer to expose a configuration option instead of hard-coding this behaviour. That way we can preserve backwards compatibility. functionerrorHandler(options){if(options.includeStack!==false){// original error handler}else{// remove stack}}The configuration - {
"final:after": {
"loopback#errorHandler": {
"params": {
"includeStack": false
}
}
}Thoughts? |
digitalsadhu
commented
Jul 7, 2015
Yes thats nicer, will make the change |
digitalsadhu
commented
Jul 8, 2015
will look into fixing tests shortly |
digitalsadhu
commented
Jul 9, 2015
Tests are passing locally, under iojs, 0.10 and 0.12 so not sure whats going on with Travis. @bajtos How is this looking now? |
bajtos
commented
Jul 10, 2015
Did you run |
There was a problem hiding this comment.
Nitpick: group by property name, not by operations.
loopback.urlNotFound = loopback['url-not-found'];
delete loopback['url-not-found'];
loopback.errorHandler = loopback['error-handler'];
delete loopback['error-handler'];
In this particular case, I'd personally keep loopback[error-handler] so that it can be loaded in middleware.json via loopback#error-handler. Not a big deal though.
bajtos
commented
Jul 10, 2015
Thank you for the update @digitalsadhu. I am starting a long (3 weeks+) paternity leave on Monday, it's likely that I won't be able to continue reviewing this patch as timely as I'd like. Sorry for that. |
bajtos
commented
Jul 10, 2015
@slnode ok to test |
digitalsadhu
commented
Jul 12, 2015
Thanks @bajtos. I'm on paternity leave 3 days/week myself. Enjoy :) |
bajtos
commented
Aug 24, 2015
@digitalsadhu ping, what's the status of this pull request? Are you still keen to get it finished & landed? |
Removes stack trace in production mode. Signed-off-by: Richard Walker <digitalsadhu@gmail.com>
Signed-off-by: Richard Walker <digitalsadhu@gmail.com>
This is now done in the new error handler middleware module Signed-off-by: Richard Walker <digitalsadhu@gmail.com>
Instead of removing stack when NODE_ENV=production, instead remove stack when options.includeStack === false Signed-off-by: Richard Walker <digitalsadhu@gmail.com>
Signed-off-by: Richard Walker <digitalsadhu@gmail.com>
f5d8aea to
07666d4Comparedigitalsadhu
commented
Sep 2, 2015
@bajtos sorry for the delay, I have made fixes based on your comments, rebased loopback master onto my branch and pushed. How are we looking? Also, question. Express is logging to the console during tests which is a bit ugly. Whats the best way to disable this? |
bajtos
commented
Sep 2, 2015
Thank you, the patch LGTM now.
I believe you can pass |
There was a problem hiding this comment.
One more thing to address. errorhandler is a devDependency, thus this line will thrown when loopback is installed in a project that does not have errorhandler in project's dependencies.
Please make errorhandler a regular dependency in loopback's package.json
bajtos
commented
Sep 2, 2015
@digitalsadhu I am looking forward to land this patch! Please remove console logs from unit tests and fix the comment above first, or let me know whether I should make these two small changes myself. |
It looks like I had missed this. I realised when I tried to disable console logging and found that the options I passed to the loopback error handler were not getting passed on to the errorHandler module
This test ensures that options passed to the loopback error handler get passed on to express error handler
digitalsadhu
commented
Sep 2, 2015
|
bajtos
commented
Sep 3, 2015
Haha, good catch! I appreciate you added a unit-test for that too 👍 |
There was a problem hiding this comment.
Creating a new expressErrorHandler(options) for each request is suboptimal, it's better to call it only once. I'll fix this myself to speed things up.
bajtos
commented
Sep 3, 2015
Landed via 57e40cf, thank you for the contribution! |
bajtos
commented
Sep 3, 2015
Note: when |
When running in production, supress error stack traces from the error responses (pages). This change affects the global error handler used, it does not affect strong-remoting's REST handler. See strongloop/loopback#1502
When running in production, supress error stack traces from the error responses (pages). This change affects the global error handler used, it does not affect strong-remoting's REST handler. See strongloop/loopback#1502
Creates a new loopback.errorHandler function that wraps the existing express errorhandler module and essentially just unsets the stack trace when the app is in production.
Note, a modification to middleware.json file generation will need to occur for this approach to work.
will need to change to:
Fixes#564
@bajtos This is my attempt to solve this issue. Thoughts?
If you like the approach I can put some more effort into writing tests and documentation. If you would prefer another approach, please advise.