@avonjs/avonjs
Version:
A fluent Node.js API generator.
40 lines (39 loc) • 1.23 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const collect_js_1 = require("collect.js");
const ErrorResponse_1 = __importDefault(require("../Http/Responses/ErrorResponse"));
const ResponsableException_1 = __importDefault(require("./ResponsableException"));
class ValidationException extends ResponsableException_1.default {
errors;
constructor(errors) {
super('The given data was invalid.');
this.errors = errors;
}
/**
* Get the response code
*/
getCode() {
return 422;
}
/**
* Get the exception name
*/
getName() {
return 'UnprocessableContent';
}
/**
* Create an HTTP response that represents the object.
*/
toResponse() {
return new ErrorResponse_1.default(this.getCode(), this.getName(), this.message).withMeta('errors', (0, collect_js_1.collect)(this.errors.details)
.mapWithKeys((error) => [
error.path,
error.message,
])
.all());
}
}
exports.default = ValidationException;