Merge pull request #423 from CartoDB/multierror-support

Adds support to return multiple errors in BaseController.sendError
This commit is contained in:
Raul Ochoa 2016-04-21 16:15:28 +02:00
commit 83eceb349c
2 changed files with 7 additions and 1 deletions

View File

@ -4,6 +4,9 @@
Released 2016-mm-dd Released 2016-mm-dd
Enhancements:
- Adds support to return multiple errors in BaseController.sendError #423
## 2.33.1 ## 2.33.1

View File

@ -197,7 +197,10 @@ BaseController.prototype.send = function(req, res, body, status, headers) {
// jshint maxcomplexity:6 // jshint maxcomplexity:6
BaseController.prototype.sendError = function(req, res, err, label) { BaseController.prototype.sendError = function(req, res, err, label) {
var allErrors = Array.isArray(err) ? err : [err];
label = label || 'UNKNOWN'; label = label || 'UNKNOWN';
err = allErrors[0] || new Error(label);
allErrors[0] = err;
var statusCode = findStatusCode(err); var statusCode = findStatusCode(err);
@ -208,7 +211,7 @@ BaseController.prototype.sendError = function(req, res, err, label) {
statusCode = 200; statusCode = 200;
} }
var errorResponseBody = { errors: [errorMessage(err)] }; var errorResponseBody = { errors: allErrors.map(errorMessage) };
this.send(req, res, errorResponseBody, statusCode); this.send(req, res, errorResponseBody, statusCode);
}; };