-
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.
Return some error codes when adding peers
Partly addresses #925. Not finished.
- Loading branch information
Showing
4 changed files
with
51 additions
and
8 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,20 @@ | ||
/** | ||
* Create an `Error` with a `code` property. | ||
* | ||
* @example | ||
* const err = new ErrorWithCode('INVALID_DATA', 'data was invalid') | ||
* err.message | ||
* // => 'data was invalid' | ||
* err.code | ||
* // => 'INVALID_DATA' | ||
*/ | ||
export class ErrorWithCode extends Error { | ||
/** | ||
* @param {string} code | ||
* @param {string} message | ||
*/ | ||
constructor(code, message) { | ||
super(message) | ||
/** @readonly */ this.code = code | ||
} | ||
} |
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,10 @@ | ||
import assert from 'node:assert/strict' | ||
import test from 'node:test' | ||
import { ErrorWithCode } from '../../src/lib/error-with-code.js' | ||
|
||
test('ErrorWithCode', () => { | ||
const err = new ErrorWithCode('MY_CODE', 'my message') | ||
assert.equal(err.code, 'MY_CODE') | ||
assert.equal(err.message, 'my message') | ||
assert(err instanceof Error) | ||
}) |