Treat 404 from a URL as missing file, not fatal error

This commit is contained in:
Pavel Yakunin 2014-12-28 18:15:44 +03:00 committed by Havoc Pennington
parent f3e11bc583
commit 7f19e46d1c

View File

@ -463,6 +463,7 @@ public abstract class Parseable implements ConfigParseable {
@Override
protected Reader reader(ConfigParseOptions options) throws IOException {
try {
if (ConfigImpl.traceLoadsEnabled())
trace("Loading config from a URL: " + input.toExternalForm());
URLConnection connection = input.openConnection();
@ -489,6 +490,19 @@ public abstract class Parseable implements ConfigParseable {
InputStream stream = connection.getInputStream();
return readerFromStream(stream);
} catch (FileNotFoundException fnf) {
// If the resource is not found (HTTP response
// code 404 or something alike), then it's fine to
// treat it according to the allowMissing setting
// and "include" spec. But if we have something
// like HTTP 503 it seems to be better to fail
// early, because this may be a sign of broken
// environment. Java throws FileNotFoundException
// if it sees 404 or 410.
throw fnf;
} catch (IOException e) {
throw new ConfigException.BugOrBroken("Cannot load config from URL: " + input.toExternalForm(), e);
}
}
@Override