wordnik/swagger-node-express — pull request #77 by pascal-bach (2013-11-17 16:07:03+00:00)
Title: Export errorHandler method

Exporting the errorHandler method as public API allows handling of errors in async code.

Example:
var swagger = require("swagger-node-express");

exports.remove = {
'spec' : {
"description" : "Deletes an object",
"path" : "/objects/{id}",
"notes" : "",
"summary" : "",
"method" : "DELETE",
"params" : [swagger.pathParam("id", "ID of object to delete", "string")],
"errorResponses" : [ swagger.errors.notFound('id'), swagger.errors.invalid('id') ],
"nickname" : "remove"
},
'action' : function(req, res) {

if (!req.params.id) {
throw swagger.errors.invalid('id');
}

req.coll.removeById(req.params.id, function(err, result) {
if (err) {
swagger.errorHandler(req, res, swagger.errors.invalid('collection'));
}

res.send({msg : 'success'});
});
}
};