Include error codes

master
Sven Slootweg 4 years ago
parent 8fdab33e8b
commit edd06a6a94

@ -27,13 +27,13 @@ module.exports = function (protocols) {
: null; : null;
if (parsedProtocol == 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())) { } else if (protocolSet != null && !protocolSet.has(parsedProtocol.toLowerCase())) {
let validProtocolList = protocols let validProtocolList = protocols
.map((protocol) => protocol.toUpperCase()) .map((protocol) => protocol.toUpperCase())
.join(", "); .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 { } else {
return parsed; return parsed;
} }

Loading…
Cancel
Save