Comparing version 2.2.0 to 2.2.1
@@ -0,1 +1,8 @@ | ||
var DOCUMENT_NOT_FOUND_REGEX = new RegExp('^The query did not find a document and returned null.*'); | ||
module.exports.DOCUMENT_NOT_FOUND_REGEX = DOCUMENT_NOT_FOUND_REGEX; | ||
var DUPLICATE_PRIMARY_KEY_REGEX = new RegExp('^Duplicate primary key.*'); | ||
module.exports.DUPLICATE_PRIMARY_KEY_REGEX = DUPLICATE_PRIMARY_KEY_REGEX; | ||
/** | ||
@@ -9,3 +16,4 @@ * DocumentNotFound error which is returned when `get` returns `null`. | ||
}; | ||
DocumentNotFound.prototype = new Error(); | ||
DocumentNotFound.prototype = Object.create(Error.prototype); | ||
DocumentNotFound.prototype.constructor = DocumentNotFound; | ||
DocumentNotFound.prototype.name = "Document not found"; | ||
@@ -25,3 +33,4 @@ module.exports.DocumentNotFound = DocumentNotFound; | ||
}; | ||
InvalidWrite.prototype = new Error(); | ||
InvalidWrite.prototype = Object.create(Error.prototype); | ||
InvalidWrite.prototype.constructor = InvalidWrite; | ||
InvalidWrite.prototype.name = "Invalid write"; | ||
@@ -39,4 +48,36 @@ module.exports.InvalidWrite = InvalidWrite; | ||
}; | ||
ValidationError.prototype = new Error(); | ||
ValidationError.prototype = Object.create(Error.prototype); | ||
ValidationError.prototype.constructor = ValidationError; | ||
ValidationError.prototype.name = "Document failed validation"; | ||
module.exports.ValidationError = ValidationError; | ||
/** | ||
* DuplicatePrimaryKey error which is returned when the primary key unique constraint of a document fails. | ||
* "Extends" Error | ||
*/ | ||
function DuplicatePrimaryKey(message) { | ||
Error.captureStackTrace(this, DuplicatePrimaryKey); | ||
this.message = message; | ||
}; | ||
DuplicatePrimaryKey.prototype = new Error(); | ||
DuplicatePrimaryKey.prototype.name = "Duplicate primary key"; | ||
module.exports.DuplicatePrimaryKey = DuplicatePrimaryKey; | ||
module.exports.create = function (errorOrMessage) { | ||
var message = (errorOrMessage instanceof Error) ? errorOrMessage.message : errorOrMessage; | ||
if(message.match(DOCUMENT_NOT_FOUND_REGEX)) { | ||
return new DocumentNotFound(message); | ||
} | ||
if(message.match(DUPLICATE_PRIMARY_KEY_REGEX)) { | ||
return new DuplicatePrimaryKey(message); | ||
} | ||
if (errorOrMessage instanceof Error) { | ||
return errorOrMessage; | ||
} | ||
return new Error(errorOrMessage); | ||
}; |
@@ -200,8 +200,3 @@ var Promise = require('bluebird'); | ||
}).catch(function(err) { | ||
var notFoundRegex = new RegExp('^' + new Errors.DocumentNotFound().message); | ||
if (err.message.match(notFoundRegex)) { | ||
//Reject with an instance of Errors.DocumentNotFound | ||
err = new Errors.DocumentNotFound(err.message); | ||
} | ||
return Promise.reject(err); | ||
return Promise.reject(Errors.create(err)); | ||
}) | ||
@@ -208,0 +203,0 @@ }; |
{ | ||
"name": "thinky", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "RethinkDB ORM for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/thinky.js", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
220876
5933