Level / community

Discussion, support and common information for projects in the community.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting no entry found error in Chrome when using .get("key")

kevinkyle4 opened this issue · comments

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

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')
  }
}

Something like this should work:

let value = null
try {
  value = await db.get('key')
} catch (err) {
  if (err.type !== 'NotFoundError') {
    throw err
  }
}

above solved my issue. thanks