Need validateResponse to throw an error for invalid responses, if no responseValidationFn is passed.
res.set('Content-Type', ''); // Reset content-type since it is no longer valid
}
err.failedValidation = true;
err.message = 'Value expected to be an array/object but is not';
if (options.responseValidationFn) {
options.responseValidationFn(req, data, [err]);
sendData(res, data, encoding);
return;
}
const resultError = {
message: `Response schema validation failed for ${req.method}${req.originalUrl}`,
};
if (options.returnResponseErrors) {
err.errors = [{ message: 'Invalid response format' }];
}
next(resultError);
return;```
Need this to behave like validateRequest, where if there's no `options.requestValidationFn` and the request is invalid, the method sends 400 status with the error.
Need
validateResponse
to throw an error for invalid responses, if noresponseValidationFn
is passed.