-
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.
chore: use
NotFoundError
utility in more places (#965)
This makes the following kind of change in a bunch of places: ```diff -throw new Error('Not found') +throw new NotFoundError() ``` I think this is a useful improvement on its own, but the changes to DataStore will also make [an upcoming change easier][0]. [0]: #188
- Loading branch information
Showing
6 changed files
with
33 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export class NotFoundError extends Error { | ||
constructor() { | ||
super('Not found') | ||
constructor(message = 'Not found') { | ||
super(message) | ||
} | ||
} |
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,17 @@ | ||
import test, { describe } from 'node:test' | ||
import assert from 'node:assert/strict' | ||
import { NotFoundError } from '../src/errors.js' | ||
|
||
describe('NotFoundError', () => { | ||
test('subclasses Error', () => { | ||
assert(new NotFoundError() instanceof Error) | ||
}) | ||
|
||
test('with no error message', () => { | ||
assert.equal(new NotFoundError().message, 'Not found') | ||
}) | ||
|
||
test('with custom error message', () => { | ||
assert.equal(new NotFoundError('foo').message, 'foo') | ||
}) | ||
}) |