Comparing version 2.0.1 to 2.1.0
# Changelog | ||
## Version 2.1.0 - Oct 20, 2016 | ||
* Add optional log function parameter to the constructor. This allows clients to dirrect errors to their own logging infrastructure | ||
## Version 2.0.1 - Aug 28, 2016 | ||
@@ -4,0 +7,0 @@ * Fix critical bug, the implementation code base was not bundled in the npm package because of the way .npmignore works with .gitignore in node v6. |
@@ -28,2 +28,3 @@ /** | ||
* @option options {String} namespace placeholder for custom data and methods. | ||
* @option options {Function} log is a function(level, message, args...) {} | ||
*/ | ||
@@ -56,2 +57,10 @@ constructor (Model, options = {}) { | ||
this.ns = options.namespace || 'mrt'; | ||
// @property {Function} a function to log messages. Defaults to noop. | ||
if (this.is('Function', options.log)) { | ||
this.log = options.log; | ||
} | ||
else { | ||
this.log = () => {}; // noop. | ||
} | ||
} | ||
@@ -281,3 +290,5 @@ | ||
if (!id) { | ||
return res.status(404).send({msg: 'Document id not provided'}); | ||
return res.status(404).send({ | ||
msg: 'Document id not provided' | ||
}); | ||
} | ||
@@ -307,4 +318,5 @@ | ||
const document = new this.Model(req.body); | ||
document.save((errors) => { | ||
if (errors) { | ||
document.save((error) => { | ||
if (error) { | ||
this.log('error', 'Failed to store document', error); | ||
return res.status(500).send({ | ||
@@ -340,3 +352,6 @@ msg: 'Error storing new document' | ||
if (error) { | ||
return res.status(500).send({msg: 'Error patching document'}); | ||
this.log('error', 'Failed to patch document', error); | ||
return res.status(500).send({ | ||
msg: 'Error patching document' | ||
}); | ||
} | ||
@@ -362,2 +377,3 @@ return next(); | ||
if (error) { | ||
this.log('error', 'Failed to read document for update', error); | ||
return res.status(500).send({ | ||
@@ -372,2 +388,3 @@ msg: 'Failed to replace the document' | ||
if (error) { | ||
this.log('error', 'Failed to update document', error); | ||
return res.status(500).send({ | ||
@@ -397,2 +414,3 @@ msg: 'Error replacing document' | ||
if (error) { | ||
this.log('error', 'Failed to remove document', error); | ||
return res.status(500).send({ | ||
@@ -435,2 +453,3 @@ msg: 'error removing document' | ||
if (error) { | ||
this.log('error', 'Failed to update collection', error); | ||
return res.status(500).send({ | ||
@@ -455,2 +474,3 @@ msg: 'Unable to patch selected documents' | ||
if (error) { | ||
this.log('error', 'Failed to remove collection', error); | ||
return res.status(500).send({ | ||
@@ -479,2 +499,3 @@ msg: 'Failed to remove selected documents' | ||
if (error) { | ||
this.log('error', 'Failed to count documents', error); | ||
return res.status(500).send({ | ||
@@ -503,2 +524,3 @@ msg: 'Error counting documents' | ||
if (error) { | ||
this.log('error', 'Failed to execute mongoose query', error); | ||
return res.status(500).send({ | ||
@@ -505,0 +527,0 @@ msg: error.message |
{ | ||
"name": "mortimer", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "rest interface for mongoose models, built on top of express", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/topliceanu/mortimer", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
38532
20
711