diff --git a/src/fetch-error.js b/src/fetch-error.js index a417919..4d4b932 100644 --- a/src/fetch-error.js +++ b/src/fetch-error.js @@ -16,9 +16,6 @@ export default function FetchError(message, type, systemError) { Error.call(this, message); - // hide custom error implementation details from end-users - Error.captureStackTrace(this, this.constructor); - this.message = message; this.type = type; @@ -27,7 +24,10 @@ export default function FetchError(message, type, systemError) { this.code = this.errno = systemError.code; } + // hide custom error implementation details from end-users + Error.captureStackTrace(this, this.constructor); } FetchError.prototype = Object.create(Error.prototype); +FetchError.prototype.constructor = FetchError; FetchError.prototype.name = 'FetchError'; diff --git a/test/test.js b/test/test.js index 1c26044..ae4972b 100644 --- a/test/test.js +++ b/test/test.js @@ -1819,7 +1819,7 @@ describe(`node-fetch with FOLLOW_SPEC = ${defaultFollowSpec}`, () => { expect(body).to.have.property('buffer'); }); - it('should create custom FetchError', function() { + it('should create custom FetchError', function funcName() { const systemError = new Error('system'); systemError.code = 'ESOMEERROR'; @@ -1831,6 +1831,8 @@ describe(`node-fetch with FOLLOW_SPEC = ${defaultFollowSpec}`, () => { expect(err.type).to.equal('test-error'); expect(err.code).to.equal('ESOMEERROR'); expect(err.errno).to.equal('ESOMEERROR'); + expect(err.stack).to.include('funcName') + .and.to.startWith(`${err.name}: ${err.message}`); }); it('should support https request', function() {