Add error body with info when none of labels found (#1461)
This commit is contained in:
committed by
Spencer Gibb
parent
6d64def1ae
commit
ef14f4abc5
@@ -130,6 +130,7 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator
|
||||
return composite;
|
||||
}
|
||||
}
|
||||
errorBody = String.format("None of labels %s found", Arrays.toString(labels));
|
||||
}
|
||||
catch (HttpServerErrorException e) {
|
||||
error = e;
|
||||
@@ -147,8 +148,7 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator
|
||||
+ (errorBody == null ? "" : ": " + errorBody),
|
||||
error);
|
||||
}
|
||||
logger.warn("Could not locate PropertySource: " + (errorBody == null
|
||||
? error == null ? "label not found" : error.getMessage() : errorBody));
|
||||
logger.warn("Could not locate PropertySource: " + (error != null ? error.getMessage() : errorBody));
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@@ -111,12 +111,29 @@ public class ConfigServicePropertySourceLocatorTests {
|
||||
@Test
|
||||
public void sunnyDayWithNoSuchLabel() {
|
||||
mockRequestResponseWithLabel(
|
||||
new ResponseEntity<Void>((Void) null, HttpStatus.NOT_FOUND),
|
||||
new ResponseEntity<>((Void) null, HttpStatus.NOT_FOUND),
|
||||
"nosuchlabel");
|
||||
this.locator.setRestTemplate(this.restTemplate);
|
||||
assertThat(this.locator.locate(this.environment)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sunnyDayWithNoSuchLabelAndFailFast() {
|
||||
ConfigClientProperties defaults = new ConfigClientProperties(this.environment);
|
||||
defaults.setFailFast(true);
|
||||
this.locator = new ConfigServicePropertySourceLocator(defaults);
|
||||
mockRequestResponseWithLabel(
|
||||
new ResponseEntity<>((Void) null, HttpStatus.NOT_FOUND),
|
||||
"release(_)v1.0.0");
|
||||
this.locator.setRestTemplate(this.restTemplate);
|
||||
TestPropertyValues.of("spring.cloud.config.label:release/v1.0.1")
|
||||
.applyTo(this.environment);
|
||||
this.expected.expect(IsInstanceOf.instanceOf(IllegalStateException.class));
|
||||
this.expected.expectMessage(
|
||||
"Could not locate PropertySource and the fail fast property is set, failing: None of labels [release/v1.0.1] found");
|
||||
this.locator.locate(this.environment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failsQuietly() {
|
||||
mockRequestResponseWithoutLabel(
|
||||
|
||||
Reference in New Issue
Block a user