Add input validation

master
Sven Slootweg 5 years ago
parent 03235124e3
commit 4ad1f5f0fb

@ -7,7 +7,7 @@ const url = require("url");
const asExpression = require("as-expression");
const dotty = require("dotty");
const getJson = require("axios-get-json-response");
const { ValidationError, validateValue, required, isString, arrayOf, allowExtraProperties } = require("validatem");
const { ValidationError, validateValue, validateArguments, required, isString, arrayOf, allowExtraProperties } = require("validatem");
let LookupFailed = createError("LookupFailed");
let MethodNotAvailable = createError("MethodNotAvailable");
@ -155,11 +155,15 @@ function attemptWellKnown(host) {
module.exports = {
LookupFailed: LookupFailed,
discover: function (host) {
discover: function (hostname) {
validateArguments(arguments, [
["hostname", required, isString]
]);
return Promise.try(() => {
return attemptWellKnown(host);
return attemptWellKnown(hostname);
}).catch(MethodNotAvailable, () => {
return attemptLiteralHostname(host);
return attemptLiteralHostname(hostname);
}).catch(MethodNotAvailable, () => {
throwLookupError("none of the autodiscovery methods were available");
});

Loading…
Cancel
Save