Skip to content

Commit 314977c

Browse files
committed
Introducing not found error for config values
1 parent 62cc749 commit 314977c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const _get = require('just-safe-get')
66
const _set = require('just-safe-set')
77
const _has = require('lodash.has')
88
const errcode = require('err-code')
9+
const errors = require('./errors')
910

1011
const configKey = new Key('config')
1112

@@ -27,7 +28,7 @@ module.exports = (store) => {
2728
const encodedValue = await store.get(configKey)
2829
const config = JSON.parse(encodedValue.toString())
2930
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`)
3132
}
3233

3334
const value = key !== undefined ? _get(config, key) : config

src/errors/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
'use strict'
22

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+
318
exports.ERR_REPO_NOT_INITIALIZED = 'ERR_REPO_NOT_INITIALIZED'
419
exports.ERR_REPO_ALREADY_OPEN = 'ERR_REPO_ALREADY_OPEN'
520
exports.ERR_REPO_ALREADY_CLOSED = 'ERR_REPO_ALREADY_CLOSED'

0 commit comments

Comments
 (0)