UNPKG

swagger-generator-koa

Version:
27 lines (26 loc) 830 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = require("lodash"); function ValidationError(errors, options) { this.name = 'ValidationError'; this.message = 'validation error'; this.errors = errors; this.flatten = options.flatten; this.status = options.status; this.statusText = options.statusText; } ValidationError.prototype = Object.create(Error.prototype); ValidationError.prototype.toString = function () { return JSON.stringify(this.toJSON()); }; ValidationError.prototype.toJSON = function () { if (this.flatten) { return lodash_1.flatten(lodash_1.map(this.errors, 'messages')); } return { status: this.status, statusText: this.statusText, errors: this.errors }; }; exports.default = ValidationError;