diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f7b731..14b132c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [18, 20, 22] + node-version: [18, 20, 22, 26] steps: - name: Checkout uses: actions/checkout@v5 diff --git a/lib/baseClasses/HttpError.js b/lib/baseClasses/HttpError.js index d5f0428..db82687 100644 --- a/lib/baseClasses/HttpError.js +++ b/lib/baseClasses/HttpError.js @@ -149,8 +149,8 @@ HttpError.prototype.toJSON = function toJSON() { var message = ''; // if we have a cause, get the full VError toString() without the current - // error name. verbose check, self.cause can exist but returns undefined - if (self.cause && typeof self.cause === 'function' && self.cause()) { + // error name. + if (self.cause) { var fullString = self.toString(); message = fullString.substr(fullString.indexOf(' ') + 1); } else { @@ -159,8 +159,7 @@ HttpError.prototype.toJSON = function toJSON() { return { code: self.body.code, - message: message, - cause: self.cause + message: message }; }; diff --git a/lib/serializer.js b/lib/serializer.js index 0ccd264..517fa84 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -71,7 +71,7 @@ function _getMultiErrorStack(err) { /** - * loop through all cause() errors and build a stack trace output + * loop through all cause errors and build a stack trace output * @private * @method _getFullErrorStack * @param {Object} err an error object @@ -94,7 +94,7 @@ function _getFullErrorStack(err) { out += stackString.shift() + self._getSerializedContext(e); out += stackString.join('\n'); - e = (typeof e.cause === 'function') ? e.cause() : null; + e = e.cause || null; first = false; } while (e); diff --git a/package.json b/package.json index de848c1..1a04d44 100644 --- a/package.json +++ b/package.json @@ -51,8 +51,11 @@ "optionalDependencies": { "safe-json-stringify": "^1.2.0" }, + "overrides": { + "@netflix/nerror": "2.0.0-rc.0" + }, "dependencies": { - "@netflix/nerror": "^1.1.3", + "@netflix/nerror": "2.0.0-rc.0", "assert-plus": "^1.0.0", "lodash": "^4.17.21" } diff --git a/test/index.js b/test/index.js index dd248f7..078bd2d 100644 --- a/test/index.js +++ b/test/index.js @@ -76,7 +76,7 @@ describe('restify-errors node module.', function() { var priorErr = new Error('foobar'); var myErr = new HttpError(priorErr, 'new message'); - assert.equal(myErr.cause(), priorErr); + assert.equal(myErr.cause, priorErr); assert.equal(myErr.name, 'HttpError'); assert.equal(myErr.message, 'new message'); assert.isObject(myErr.body); @@ -89,7 +89,7 @@ describe('restify-errors node module.', function() { cause: priorErr }, myErr2Msg); - assert.equal(myErr2.cause(), priorErr); + assert.equal(myErr2.cause, priorErr); assert.equal(myErr2.name, 'HttpError'); assert.equal(myErr2.message, myErr2Msg); assert.isObject(myErr2.body); @@ -193,7 +193,7 @@ describe('restify-errors node module.', function() { var priorErr = new Error('foobar'); var myErr = new httpErrors.BadGatewayError(priorErr); - assert.equal(myErr.cause(), priorErr); + assert.equal(myErr.cause, priorErr); assert.equal(myErr.name, 'BadGatewayError'); assert.equal(myErr.statusCode, 502); assert.isObject(myErr.body); @@ -205,7 +205,7 @@ describe('restify-errors node module.', function() { cause: priorErr }, myErr2Msg); - assert.equal(myErr.cause(), priorErr); + assert.equal(myErr.cause, priorErr); assert.equal(myErr2.name, 'BadGatewayError'); assert.equal(myErr2.statusCode, 502); assert.equal(myErr2.message, myErr2Msg); @@ -272,7 +272,7 @@ describe('restify-errors node module.', function() { var priorErr = new Error('foobar'); var myErr = new RestError(priorErr); - assert.equal(myErr.cause(), priorErr); + assert.equal(myErr.cause, priorErr); assert.equal(myErr.name, 'RestError'); assert.equal(myErr.restCode, 'Error'); assert.equal(myErr.message, ''); @@ -288,7 +288,7 @@ describe('restify-errors node module.', function() { }; var myErr2 = new RestError(options, errMsg); - assert.equal(myErr2.cause(), priorErr); + assert.equal(myErr2.cause, priorErr); assert.equal(myErr2.name, 'RestError'); assert.equal(myErr2.restCode, options.restCode); assert.equal(myErr2.message, errMsg); @@ -605,7 +605,7 @@ describe('restify-errors node module.', function() { assert.isObject(err.body); assert.equal(err.body.code, 'Execution'); assert.equal(err.body.message, 'bad joystick input'); - assert.equal(err.cause(), underlyingErr); + assert.equal(err.cause, underlyingErr); // assert stringification var expectedJSON = { @@ -646,7 +646,7 @@ describe('restify-errors node module.', function() { assert.isObject(err.body); assert.equal(err.body.code, 'Execution'); assert.equal(err.body.message, 'bad joystick input'); - assert.equal(err.cause(), underlyingErr); + assert.equal(err.cause, underlyingErr); assert.deepEqual(restifyErrors.info(err), { foo: 'bar', baz: [ 1, 2, 3 ]