mirror of
https://github.com/lightbend/config.git
synced 2025-03-30 22:20:38 +08:00
Treat 404 from a URL as missing file, not fatal error
This commit is contained in:
parent
f3e11bc583
commit
7f19e46d1c
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user