AndrewKeig/express-validation

option flatten behaves unreasonable

Closed this issue · 3 comments

Hi:
when I wrote a middleware to handle the error, I passed a option 'flatten', then I got an unexpected result. I read the code, and maybe that is the problem.
The origin code:

 ValidationError.prototype.toJSON = function () {
    if (this.flatten) return flatten(map(this.errors, 'messages'));
    return {
      status: this.status,
      statusText: this.statusText,
      errors: this.errors
    };
  };

or mybe it should be:

ValidationError.prototype.toJSON = function toJSON() {
    return {
      status: this.status,
      statusText: this.statusText,
      errors: this.flatten ? flatten(map(this.errors, 'messages')) : this.errors
    };
  };

Not sure if it is a bug, waiting for ur answer, thx!

Indeed, you seem correct

@colthreepv ok,waitting for ur fix (^ _ ^)

Fixed