-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eerror): Add main code and tests
- Loading branch information
1 parent
2116f15
commit 1d5d558
Showing
2 changed files
with
28 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class EError extends Error { | ||
constructor(message, ...args) { | ||
super(message); | ||
this.name = 'EError'; | ||
|
||
for (let i = 0; i < args.length; i += 1) { | ||
if (typeof args[i] === 'object') { | ||
Object.assign(this, args[i]); | ||
} else { | ||
this[`param${i + 1}`] = args[i]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
module.exports = EError; |
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,12 @@ | ||
import test from 'ava'; | ||
import EError from './index'; | ||
|
||
test('eerror - smoke test', (t) => { | ||
t.notThrows(() => { | ||
const error = new EError('Message', 'val1', { success: true }); | ||
t.true(error instanceof Error); | ||
t.is(typeof error.stack, 'string'); | ||
t.is(error.param1, 'val1'); | ||
t.is(error.success, true); | ||
}); | ||
}); |