Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/jsonrpc-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ JsonRpcAdapter.prototype.getRoutes = function(obj) {
return routes;
};

JsonRpcAdapter.errorHandler = function() {
JsonRpcAdapter.strongErrorHandler = function() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this API rename? Why can't we keep existing errorHandler name?

return function restErrorHandler(err, req, res, next) {
if (typeof err === 'string') {
err = new Error(err);
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions lib/rest-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -341,7 +341,7 @@ RestAdapter.urlNotFoundHandler = function() {
};
};

RestAdapter.errorHandler = function(options) {
RestAdapter.strongErrorHandler = function(options) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to change the implementation to use the new strong-error-handler module under the hood, the method names (API) can stay the same, no need to change that.

options = options || {};
return function restErrorHandler(err, req, res, next) {
if (typeof options.handler === 'function') {
Expand Down Expand Up @@ -397,7 +397,7 @@ RestAdapter.errorHandler = 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;
}

Expand Down
7 changes: 3 additions & 4 deletions test/rest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('strong-remoting-rest', function() {
process.env.NODE_ENV = 'test';
}
objects = RemoteObjects.create({ json: { limit: '1kb' },
errorHandler: { disableStackTrace: false }});
strongErrorHandler: { debug: true }});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should preserve backwards compatibility in the sense that it is still possible to configure the error handler via errorHandler: { disableStackTrace: false }}.

Note that the fact that we use strong-error-handler under the hood is just an implementation detail that API consumers should not need to know about.

remotes = objects.exports;

// connect to the app
Expand Down Expand Up @@ -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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, this line should not need to be changed, the old API should continue to work in the new version.

expect(err.message).to.contain('foo');
err = new Error('foobar');
called = true;
Expand All @@ -127,7 +127,7 @@ describe('strong-remoting-rest', function() {
});

it('should disable stack trace', function(done) {
objects.options.errorHandler.disableStackTrace = true;
objects.options.strongErrorHandler.debug = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, this line should not need to be changed, the old API should continue to work in the new version.

If you prefer, then we can support both settings debug:false and disableStackTrace:true, but it's important to ensure that disableStackTrace keeps working.

However, while you are making this change, please change the default value of disableStackTrace to true, so that apps are configured for security by default.

var method = givenSharedStaticMethod(
function(cb) {
cb(new Error('test-error'));
Expand Down Expand Up @@ -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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change needed? I don't mind much, I just want to ensure we fully understand why we are making it.

});
});
Expand Down