Browse Source

Include error codes

master
Sven Slootweg 1 year ago
parent
commit
edd06a6a94
  1. 4
      index.js

4
index.js

@ -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