backbone-db
Advanced tools
Comparing version 0.4.23 to 0.4.24
@@ -5,2 +5,4 @@ var Backbone = require('backbone'); | ||
var jsonquery = require('jsonquery'); | ||
var errors = require('./errors'); | ||
var util = require('util'); | ||
@@ -179,3 +181,4 @@ var self = this; | ||
data = data && JSON.parse(data); | ||
var error = err || data ? null : new Error('not found'); | ||
var errorMsg = util.format('%s (%s) not found (read)', model.type, model.id); | ||
var error = err || data ? null : new errors.NotFoundError(errorMsg); | ||
return cb(error, data); | ||
@@ -213,3 +216,4 @@ }); | ||
if (!results || results.length === 0) { | ||
err = err || new Error('not found'); | ||
var errorMsg = util.format('%s (%s) not found (read)', model.type, model.id); | ||
err = err || new errors.NotFoundError(errorMsg); | ||
} | ||
@@ -247,3 +251,6 @@ return cb(err, results && results.length && results[0]); | ||
}); | ||
if (!found) return cb(new Error('not found')); | ||
if (!found) { | ||
var errorMsg = util.format('%s (%s) not found (destroy)', model.type, model.id); | ||
return cb(new errors.NotFoundError(errorMsg)); | ||
} | ||
self.save(function(err) { | ||
@@ -312,3 +319,4 @@ cb(err, model); | ||
} | ||
return cb(err || new Error('Cannot INC, not found.')); | ||
var errorMsg = util.format('%s (%s), cannot INC', model.type, model.id); | ||
return cb(err || new errors.NotFoundError(errorMsg)); | ||
} | ||
@@ -356,3 +364,4 @@ data = JSON.parse(data); | ||
if ((err && options.error) || (!err && !res && options.error)) { | ||
err = err || new Error('not found'); | ||
var errorMsg = util.format('%s (%s) not found', model.type, model.id); | ||
err = err || new errors.NotFoundError(errorMsg); | ||
return options.error(err, resp); | ||
@@ -359,0 +368,0 @@ } else if (options.success && res) { |
{ | ||
"name": "backbone-db", | ||
"version": "0.4.23", | ||
"version": "0.4.24", | ||
"description": "Key-Value database storage interface, localStorage and in-process implementations", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -159,3 +159,3 @@ var assert = require('assert'); | ||
error: function (model, err) { | ||
assert.equal(err.message, 'not found'); | ||
assert.equal(err.statusCode, 404); | ||
t(); | ||
@@ -176,3 +176,3 @@ } | ||
error: function (model, err) { | ||
assert.equal(err.message, 'not found'); | ||
assert.equal(err.statusCode, 404); | ||
t(); | ||
@@ -212,3 +212,3 @@ } | ||
error: function(model, err) { | ||
assert.equal(err.message, 'not found'); | ||
assert.equal(err.statusCode, 404); | ||
var m3 = new Indexed({some_id:10}); | ||
@@ -215,0 +215,0 @@ m3.fetch({ |
34856
16
958