diff --git a/pom.xml b/pom.xml index 6cb6eb0..0568650 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ io.github.piszmog cloud-config-client-autoconfig - 2.2 + 2.3 jar diff --git a/src/main/java/io/github/piszmog/cloudconfigclient/autoconfig/env/ConfigPropertySourceLocator.java b/src/main/java/io/github/piszmog/cloudconfigclient/autoconfig/env/ConfigPropertySourceLocator.java index 242dce6..82f0065 100644 --- a/src/main/java/io/github/piszmog/cloudconfigclient/autoconfig/env/ConfigPropertySourceLocator.java +++ b/src/main/java/io/github/piszmog/cloudconfigclient/autoconfig/env/ConfigPropertySourceLocator.java @@ -168,6 +168,10 @@ private Map getYAMLFile( final String directoryPath, final String fileName ) thr { final Map file; final byte[] yamlFile = fileConfigClient.getFileFromDefaultBranch( fileName, directoryPath, byte[].class ); + if ( yamlFile == null ) + { + throw new ConfigResourceException( "Failed to find file " + fileName + " from the Config Server. Ensure the file exists." ); + } try { file = YAML_MAPPER.readValue( yamlFile, Map.class ); @@ -182,9 +186,14 @@ private Map getYAMLFile( final String directoryPath, final String fileName ) thr private Map getPropertiesFile( final String directoryPath, final String fileName ) throws ConfigException { final Map file; + final byte[] propertiesFile = fileConfigClient.getFileFromDefaultBranch( fileName, directoryPath, byte[].class ); + if ( propertiesFile == null ) + { + throw new ConfigResourceException( "Failed to find file " + fileName + " from the Config Server. Ensure the file exists." ); + } try { - file = PROPERTIES_MAPPER.readValue( fileConfigClient.getFileFromDefaultBranch( fileName, directoryPath, byte[].class ), Map.class ); + file = PROPERTIES_MAPPER.readValue( propertiesFile, Map.class ); } catch ( IOException e ) { @@ -195,6 +204,11 @@ private Map getPropertiesFile( final String directoryPath, final String fileName private Map getJSONFile( final String directoryPath, final String fileName ) throws ConfigException { - return fileConfigClient.getFileFromDefaultBranch( fileName, directoryPath, Map.class ); + final Map jsonFile = fileConfigClient.getFileFromDefaultBranch( fileName, directoryPath, Map.class ); + if ( jsonFile == null ) + { + throw new ConfigResourceException( "Failed to find file " + fileName + " from the Config Server. Ensure the file exists." ); + } + return jsonFile; } }