Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit 557dcc8

Browse files
authored
feat(errors): document not found error when parsing non-existent results (#14)
* feat(errors): document not found error when parsing non-existent results * chore: version bump
1 parent 3e85a12 commit 557dcc8

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

lib/model/model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function createModel (requelize) {
185185
* @param {string} ModelA Model name
186186
* @param {string} ModelB Model name
187187
*/
188-
static customJoinTable(ModelA, ModelB) {
188+
static customJoinTable (ModelA, ModelB) {
189189
Model.index(ModelA)
190190
Model.index(ModelB)
191191
}

lib/model/query/query.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ class Query {
3131

3232
// enable model parsing for query result
3333
if (this._parse) {
34-
q = q.then((res) => this._Model._parse(res))
34+
q = q.then((res) => {
35+
if (res) {
36+
return this._Model._parse(res)
37+
} else {
38+
return Promise.reject(new RequelizeError('DocumentNotFound'))
39+
}
40+
})
3541
}
3642

3743
return q

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "requelize",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"description": "RethinkDB ORM",
55
"main": "index.js",
66
"repository": "https://github.com/buckless/requelize.git",

test/test.errors.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { test, requelize, dropDb } = require('./utils')
2+
3+
test('document not found error', (t) => {
4+
t.plan(2)
5+
6+
let Foo
7+
8+
dropDb()
9+
.then(() => {
10+
Foo = requelize.model('foo')
11+
12+
return requelize.sync()
13+
})
14+
.then(() => {
15+
return Foo.get('foo').run()
16+
})
17+
.catch((err) => {
18+
t.equal('RequelizeError', err.name)
19+
t.equal('DocumentNotFound', err.message)
20+
t.end()
21+
})
22+
})

0 commit comments

Comments
 (0)