@openactive/rpde-validator
Version:
A library to walk and validate an RPDE feed
49 lines (45 loc) • 1.26 kB
JavaScript
const {
ValidationErrorCategory,
ValidationErrorSeverity,
} = require('@openactive/data-model-validator');
const RpdeRule = require('../../rpde-rule');
const RpdeErrorType = require('../../errors/rpde-error-type');
const HttpStatusRule = class extends RpdeRule {
constructor() {
super();
this.meta = {
name: 'HttpStatusRule',
description: 'Validates that the response code from the server is 200',
tests: {
default: {
description: 'Raises a failure if the response code from the server is not 200',
message: 'HTTP status code should be 200, actual code returned was {{status}}',
sampleValues: {
status: 500,
},
category: ValidationErrorCategory.CONFORMANCE,
severity: ValidationErrorSeverity.FAILURE,
type: RpdeErrorType.INVALID_STATUS_CODE,
},
},
};
}
validate(node) {
if (node.data.status !== 200) {
node.log.addPageError(
node.url,
this.createError(
'default',
{
value: node.data,
url: node.url,
},
{
status: node.data.status,
},
),
);
}
}
};
module.exports = HttpStatusRule;