From 1b20bc2578c27e5050680761ad700ad631623682 Mon Sep 17 00:00:00 2001 From: Kristofer Giltvedt Selbekk Date: Thu, 23 Jul 2020 12:09:49 +0200 Subject: [PATCH] Improve error message when server is unreachable This change improves the error message for when the remote file you're trying to access is unreachable. This can happen if you misspelled the URL, the server is down for some reason or if you don't have access to the internet. --- bin/loaders/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bin/loaders/index.js b/bin/loaders/index.js index 750b91939..b67a4c122 100644 --- a/bin/loaders/index.js +++ b/bin/loaders/index.js @@ -7,7 +7,14 @@ const loadFromHttp = require("./loadFromHttp"); async function load(pathToSpec) { let rawSpec; if (/^https?:\/\//.test(pathToSpec)) { - rawSpec = await loadFromHttp(pathToSpec); + try { + rawSpec = await loadFromHttp(pathToSpec); + } catch (e) { + if (e.code === 'ENOTFOUND') { + throw new Error(`The URL ${pathToSpec} could not be reached. Ensure the URL is correct, that you're connected to the internet and that the URL is reachable via a browser.`) + } + throw e; + } } else { rawSpec = await loadFromFs(pathToSpec); }