File tree 3 files changed +27
-1
lines changed
3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ const _get = require('just-safe-get')
6
6
const _set = require ( 'just-safe-set' )
7
7
const _has = require ( 'lodash.has' )
8
8
const errcode = require ( 'err-code' )
9
+ const errors = require ( './errors' )
9
10
10
11
const configKey = new Key ( 'config' )
11
12
@@ -27,7 +28,7 @@ module.exports = (store) => {
27
28
const encodedValue = await store . get ( configKey )
28
29
const config = JSON . parse ( encodedValue . toString ( ) )
29
30
if ( key !== undefined && ! _has ( config , key ) ) {
30
- throw new Error ( `Key ${ key } does not exist in config` )
31
+ throw new errors . NotFoundError ( `Key ${ key } does not exist in config` )
31
32
}
32
33
33
34
const value = key !== undefined ? _get ( config , key ) : config
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
+ /**
4
+ * Error raised when requested item is not found.
5
+ */
6
+ class NotFoundError extends Error {
7
+ constructor ( message ) {
8
+ super ( message )
9
+ this . name = 'NotFoundError'
10
+ this . code = 'ERR_NOT_FOUND'
11
+ this . message = message
12
+ }
13
+ }
14
+
15
+ NotFoundError . code = 'ERR_NOT_FOUND'
16
+ exports . NotFoundError = NotFoundError
17
+
3
18
exports . ERR_REPO_NOT_INITIALIZED = 'ERR_REPO_NOT_INITIALIZED'
4
19
exports . ERR_REPO_ALREADY_OPEN = 'ERR_REPO_ALREADY_OPEN'
5
20
exports . ERR_REPO_ALREADY_CLOSED = 'ERR_REPO_ALREADY_CLOSED'
Original file line number Diff line number Diff line change @@ -26,5 +26,15 @@ module.exports = (repo) => {
26
26
}
27
27
} )
28
28
} )
29
+ describe ( '.get' , ( ) => {
30
+ it ( 'should throw NotFoundError when key does not exist' , async ( ) => {
31
+ try {
32
+ await repo . config . get ( 'someRandomKey' )
33
+ throw new Error ( 'Should have thrown' )
34
+ } catch ( err ) {
35
+ expect ( err . code ) . to . equal ( 'ERR_NOT_FOUND' )
36
+ }
37
+ } )
38
+ } )
29
39
} )
30
40
}
You can’t perform that action at this time.
0 commit comments