You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
955 B
JavaScript
36 lines
955 B
JavaScript
"use strict";
|
|
|
|
// const Joi = require("@hapi/joi");
|
|
|
|
const errors = require("../errors");
|
|
|
|
const {validate, ValidationError} = require("../validate");
|
|
|
|
module.exports = function createPayloadValidator(validator) {
|
|
return function validatePayload(req, _res, next) {
|
|
try {
|
|
validate(validator, req.body);
|
|
} catch (error) {
|
|
if (error instanceof ValidationError) {
|
|
console.log(require("util").inspect(error, {colors: true, depth: null}));
|
|
throw new errors.MissingParameter("Something in the validation was wrong");
|
|
} else {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
next();
|
|
|
|
|
|
// let result = Joi.validate(req.body, schema);
|
|
|
|
// if (result.error != null) {
|
|
// /* FIXME: Actually produce meaningful output based on the Joi output */
|
|
// console.log(require("util").inspect(result.error, {colors: true, depth: null}));
|
|
|
|
// throw new errors.MissingParameter("Something in the validation was wrong");
|
|
// } else {
|
|
// next();
|
|
// }
|
|
}
|
|
}; |