diff --git a/NEWS.md b/NEWS.md index 31998340..4b329ca0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,9 @@ Released 2016-mm-dd +Enhancements: + - Adds support to return multiple errors in BaseController.sendError #423 + ## 2.33.1 diff --git a/lib/cartodb/controllers/base.js b/lib/cartodb/controllers/base.js index 9945ff5a..79d4e407 100644 --- a/lib/cartodb/controllers/base.js +++ b/lib/cartodb/controllers/base.js @@ -197,7 +197,10 @@ BaseController.prototype.send = function(req, res, body, status, headers) { // jshint maxcomplexity:6 BaseController.prototype.sendError = function(req, res, err, label) { + var allErrors = Array.isArray(err) ? err : [err]; label = label || 'UNKNOWN'; + err = allErrors[0] || new Error(label); + allErrors[0] = err; var statusCode = findStatusCode(err); @@ -208,7 +211,7 @@ BaseController.prototype.sendError = function(req, res, err, label) { statusCode = 200; } - var errorResponseBody = { errors: [errorMessage(err)] }; + var errorResponseBody = { errors: allErrors.map(errorMessage) }; this.send(req, res, errorResponseBody, statusCode); };