Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Seclude ServerlessError into lib/serverless-error.js
- Loading branch information
Showing
16 changed files
with
68 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
class ServerlessError extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
this.code = code; | ||
} | ||
} | ||
|
||
Object.defineProperty(ServerlessError.prototype, 'name', { | ||
value: ServerlessError.name, | ||
configurable: true, | ||
writable: true, | ||
}); | ||
|
||
module.exports = ServerlessError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
const { expect } = require('chai'); | ||
|
||
const ServerlessError = require('../../../lib/serverless-error'); | ||
|
||
describe('test/unit/lib/serverless-error.test.js', () => { | ||
it('should store message', () => { | ||
const error = new ServerlessError('Some message'); | ||
expect(error.message).to.be.equal('Some message'); | ||
}); | ||
|
||
it('should expose constructor name', () => { | ||
const error = new ServerlessError('Some message'); | ||
expect(error.name).to.be.equal('ServerlessError'); | ||
}); | ||
|
||
it('should store code', () => { | ||
const error = new ServerlessError('Some message', 'ERROR_CODE'); | ||
expect(error.code).to.be.equal('ERROR_CODE'); | ||
}); | ||
|
||
it('message should always resolve as string', () => { | ||
const error = new ServerlessError({}); | ||
expect(typeof error.message).to.be.equal('string'); | ||
}); | ||
|
||
it('should have stack trace', () => { | ||
function testStackFrame() { | ||
throw new ServerlessError('Some message'); | ||
} | ||
|
||
try { | ||
testStackFrame(); | ||
} catch (error) { | ||
expect(error.stack).to.have.string('testStackFrame'); | ||
} | ||
}); | ||
}); |