Include error codes

master
Sven Slootweg 4 years ago
parent 8fdab33e8b
commit edd06a6a94

@ -27,13 +27,13 @@ module.exports = function (protocols) {
: null;
if (parsedProtocol == null) {
return new ValidationError("Must be a valid URL");
return new ValidationError("Must be a valid URL", { code: "validatem.is-url.invalid-url" });
} else if (protocolSet != null && !protocolSet.has(parsedProtocol.toLowerCase())) {
let validProtocolList = protocols
.map((protocol) => protocol.toUpperCase())
.join(", ");
return new ValidationError(`Must be a URL with one of the following protocols: ${validProtocolList} - but got ${parsedProtocol.toUpperCase()} instead`);
return new ValidationError(`Must be a URL with one of the following protocols: ${validProtocolList} - but got ${parsedProtocol.toUpperCase()} instead`, { code: "validatem.is-url.wrong-protocol" });
} else {
return parsed;
}

Loading…
Cancel
Save