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

Commit

Permalink
feat(errors): write-errors (#16)
Browse files Browse the repository at this point in the history
* feat(errors): write-errors
  • Loading branch information
gjuchault authored Mar 23, 2017
1 parent c44bbe6 commit 164c029
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const debug = require('debug')('requelize:model')

const Joi = require('joi')
const Query = require('./query')
const RequelizeError = require('../error')
const validateSchema = require('./util/validateSchema')
const bindSchemaToModel = require('./util/bindSchemaToModel')
const bindVirtuals = require('./util/bindVirtuals')
Expand Down Expand Up @@ -254,6 +255,11 @@ function createModel (requelize) {
.then(() => takeEvents('saving', Model, this))
.then(() => Model.parse(false).insert(this._data, { conflict: 'update' }).run())
.then((res) => {
// istanbul ignore if
if (res.errors.length > 0) {
return Promise.reject(new RequelizeError('WriteError', res.errors))
}

if (res.generated_keys) {
debug(`adding ${Model._name}:${Model._options.primaryKey} = ${res.generated_keys[0]}`)
this[Model._options.primaryKey] = res.generated_keys[0]
Expand Down Expand Up @@ -288,7 +294,12 @@ function createModel (requelize) {
.delete()
.run()
)
.then(() => {
.then((res) => {
// istanbul ignore if
if (res.errors.length > 0) {
return Promise.reject(new RequelizeError('WriteError', res.errors))
}

this[options.primaryKey] = null

return takeEvents('deleted', Model, this)
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.2",
"version": "0.6.3",
"description": "RethinkDB ORM",
"main": "index.js",
"repository": "https://github.com/buckless/requelize.git",
Expand Down

0 comments on commit 164c029

Please sign in to comment.