Getting no entry found error in Chrome when using .get("key")
kevinkyle4 opened this issue ยท 3 comments
kevinkyle4 commented
If I am trying to fetch a value by its key before the value exists in DB it throws a "Entry Not Found" error in browser which crashes app. How do I use .get() to return zero results if entry is not found like in MongoDB?
Thanks
vweevers commented
This is by design, but changing in abstract-level
2.0.0. Until then, do:
try {
await db.get('example')
} catch (err) {
if (err.code === 'LEVEL_NOT_FOUND') {
console.log('Not found')
}
}
juliangruber commented
Something like this should work:
let value = null
try {
value = await db.get('key')
} catch (err) {
if (err.type !== 'NotFoundError') {
throw err
}
}
kevinkyle4 commented
above solved my issue. thanks