Skip to content

Commit d609f0e

Browse files
authored
Improve error message when server is unreachable (#288)
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.
1 parent f9c3667 commit d609f0e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

bin/loaders/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ const loadFromHttp = require("./loadFromHttp");
77
async function load(pathToSpec) {
88
let rawSpec;
99
if (/^https?:\/\//.test(pathToSpec)) {
10-
rawSpec = await loadFromHttp(pathToSpec);
10+
try {
11+
rawSpec = await loadFromHttp(pathToSpec);
12+
} catch (e) {
13+
if (e.code === 'ENOTFOUND') {
14+
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.`)
15+
}
16+
throw e;
17+
}
1118
} else {
1219
rawSpec = await loadFromFs(pathToSpec);
1320
}

0 commit comments

Comments
 (0)