Skip to content

Commit 2a6f098

Browse files
authored
Merge pull request #28 from martin-ecatch/add_error_handling
fix(core): Add error handling to `getLocal`
2 parents 7b81e3c + 311eb0e commit 2a6f098

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/core.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -737,14 +737,18 @@ function SqlPouch(opts: OpenDatabaseOptions, cb: (err: any) => void) {
737737

738738
api._getLocal = (id: string, callback: (err: any, doc?: any) => void) => {
739739
readTransaction(async (tx: Transaction) => {
740-
const sql = 'SELECT json, rev FROM ' + LOCAL_STORE + ' WHERE id=?'
741-
const res = await tx.executeAsync(sql, [id])
742-
if (res.rows?.length) {
743-
const item = res.rows.item(0)
744-
const doc = unstringifyDoc(item.json, id, item.rev)
745-
callback(null, doc)
746-
} else {
747-
callback(createError(MISSING_DOC))
740+
try {
741+
const sql = 'SELECT json, rev FROM ' + LOCAL_STORE + ' WHERE id=?'
742+
const res = await tx.executeAsync(sql, [id])
743+
if (res.rows?.length) {
744+
const item = res.rows.item(0)
745+
const doc = unstringifyDoc(item.json, id, item.rev)
746+
callback(null, doc)
747+
} else {
748+
callback(createError(MISSING_DOC))
749+
}
750+
} catch (e: any) {
751+
handleSQLiteError(e, callback)
748752
}
749753
})
750754
}

0 commit comments

Comments
 (0)