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

Commit

Permalink
feat(errors): document not found error when parsing non-existent resu…
Browse files Browse the repository at this point in the history
…lts (#14)

* feat(errors): document not found error when parsing non-existent results

* chore: version bump
  • Loading branch information
gjuchault authored Mar 22, 2017
1 parent 3e85a12 commit 557dcc8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function createModel (requelize) {
* @param {string} ModelA Model name
* @param {string} ModelB Model name
*/
static customJoinTable(ModelA, ModelB) {
static customJoinTable (ModelA, ModelB) {
Model.index(ModelA)
Model.index(ModelB)
}
Expand Down
8 changes: 7 additions & 1 deletion lib/model/query/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ class Query {

// enable model parsing for query result
if (this._parse) {
q = q.then((res) => this._Model._parse(res))
q = q.then((res) => {
if (res) {
return this._Model._parse(res)
} else {
return Promise.reject(new RequelizeError('DocumentNotFound'))
}
})
}

return q
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "requelize",
"version": "0.6.0",
"version": "0.6.1",
"description": "RethinkDB ORM",
"main": "index.js",
"repository": "https://github.com/buckless/requelize.git",
Expand Down
22 changes: 22 additions & 0 deletions test/test.errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { test, requelize, dropDb } = require('./utils')

test('document not found error', (t) => {
t.plan(2)

let Foo

dropDb()
.then(() => {
Foo = requelize.model('foo')

return requelize.sync()
})
.then(() => {
return Foo.get('foo').run()
})
.catch((err) => {
t.equal('RequelizeError', err.name)
t.equal('DocumentNotFound', err.message)
t.end()
})
})

0 comments on commit 557dcc8

Please sign in to comment.