From c169a45de3e4c252deb41a6437e61e1262802caa Mon Sep 17 00:00:00 2001 From: Loay Gewily Date: Sun, 1 May 2016 21:50:49 -0400 Subject: [PATCH 1/2] add strongErrorHandler configuration --- lib/jsonrpc-adapter.js | 4 ++-- lib/rest-adapter.js | 4 ++-- test/rest.test.js | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/jsonrpc-adapter.js b/lib/jsonrpc-adapter.js index 66f07603..f9feaecf 100644 --- a/lib/jsonrpc-adapter.js +++ b/lib/jsonrpc-adapter.js @@ -66,7 +66,7 @@ JsonRpcAdapter.prototype.getRoutes = function(obj) { return routes; }; -JsonRpcAdapter.errorHandler = function() { +JsonRpcAdapter.strongErrorHandler = function() { return function restErrorHandler(err, req, res, next) { if (typeof err === 'string') { err = new Error(err); @@ -156,7 +156,7 @@ JsonRpcAdapter.prototype.createHandler = function() { root.use(json(jsonOptions)); - root.use(JsonRpcAdapter.errorHandler()); + root.use(JsonRpcAdapter.strongErrorHandler()); classes.forEach(function(sc) { var server = new jayson.server(); diff --git a/lib/rest-adapter.js b/lib/rest-adapter.js index 27a55074..ae075935 100644 --- a/lib/rest-adapter.js +++ b/lib/rest-adapter.js @@ -307,7 +307,7 @@ RestAdapter.prototype.createHandler = function() { if (this._shouldHandleErrors()) { // Use our own error handler to make sure the error response has // always the format expected by remoting clients. - root.use(RestAdapter.errorHandler(this.remotes.options.errorHandler)); + root.use(RestAdapter.strongErrorHandler(this.remotes.options.strongErrorHandler)); } return root; @@ -341,7 +341,7 @@ RestAdapter.urlNotFoundHandler = function() { }; }; -RestAdapter.errorHandler = function(options) { +RestAdapter.strongErrorHandler = function(options) { options = options || {}; return function restErrorHandler(err, req, res, next) { if (typeof options.handler === 'function') { diff --git a/test/rest.test.js b/test/rest.test.js index cd8c205b..9e7aa373 100644 --- a/test/rest.test.js +++ b/test/rest.test.js @@ -45,7 +45,7 @@ describe('strong-remoting-rest', function() { process.env.NODE_ENV = 'test'; } objects = RemoteObjects.create({ json: { limit: '1kb' }, - errorHandler: { disableStackTrace: false }}); + strongErrorHandler: { disableStackTrace: false }}); remotes = objects.exports; // connect to the app @@ -110,7 +110,7 @@ describe('strong-remoting-rest', function() { } ); - objects.options.errorHandler.handler = function(err, req, res, next) { + objects.options.strongErrorHandler.handler = function(err, req, res, next) { expect(err.message).to.contain('foo'); err = new Error('foobar'); called = true; @@ -127,7 +127,7 @@ describe('strong-remoting-rest', function() { }); it('should disable stack trace', function(done) { - objects.options.errorHandler.disableStackTrace = true; + objects.options.strongErrorHandler.disableStackTrace = true; var method = givenSharedStaticMethod( function(cb) { cb(new Error('test-error')); From ddb526e01796db6a2ee2521d9fcbaa44a45fdb5e Mon Sep 17 00:00:00 2001 From: Loay Gewily Date: Tue, 3 May 2016 00:54:04 -0400 Subject: [PATCH 2/2] add debug options --- lib/rest-adapter.js | 2 +- test/rest.test.js | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/rest-adapter.js b/lib/rest-adapter.js index ae075935..169dfb0d 100644 --- a/lib/rest-adapter.js +++ b/lib/rest-adapter.js @@ -397,7 +397,7 @@ RestAdapter.strongErrorHandler = function(options) { } data.stack = error.stack; - if (process.env.NODE_ENV === 'production' || options.disableStackTrace) { + if (process.env.NODE_ENV === 'production' || !options.debug) { delete data.stack; } diff --git a/test/rest.test.js b/test/rest.test.js index 9e7aa373..abea141f 100644 --- a/test/rest.test.js +++ b/test/rest.test.js @@ -45,7 +45,7 @@ describe('strong-remoting-rest', function() { process.env.NODE_ENV = 'test'; } objects = RemoteObjects.create({ json: { limit: '1kb' }, - strongErrorHandler: { disableStackTrace: false }}); + strongErrorHandler: { debug: true }}); remotes = objects.exports; // connect to the app @@ -127,7 +127,7 @@ describe('strong-remoting-rest', function() { }); it('should disable stack trace', function(done) { - objects.options.strongErrorHandler.disableStackTrace = true; + objects.options.strongErrorHandler.debug = false; var method = givenSharedStaticMethod( function(cb) { cb(new Error('test-error')); @@ -2227,7 +2227,6 @@ describe('strong-remoting-rest', function() { for (var prop in expected) { expect(result.body.error[prop], prop).to.equal(expected[prop]); } - expect(result.body.error.stack, 'stack').to.contain(__filename); done(); }); });