Merge pull request #423 from CartoDB/multierror-support
Adds support to return multiple errors in BaseController.sendError
This commit is contained in:
commit
83eceb349c
3
NEWS.md
3
NEWS.md
@ -4,6 +4,9 @@
|
||||
|
||||
Released 2016-mm-dd
|
||||
|
||||
Enhancements:
|
||||
- Adds support to return multiple errors in BaseController.sendError #423
|
||||
|
||||
|
||||
## 2.33.1
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user