Skip to content

Commit

Permalink
GH-5 NotFoundException: null
Browse files Browse the repository at this point in the history
refactor merge effects, adding extra logs
  • Loading branch information
lex-em committed Mar 25, 2019
1 parent ef0c98c commit 911880f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
@ResponseStatus(HttpStatus.NOT_FOUND)
public class NotFoundException extends RuntimeException {

public NotFoundException() {
}

public NotFoundException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,28 @@ public ObjectNode getSwaggerDoc(String route, String group) {
public List<SwaggerResource> getSwaggerResources(String route) {
Optional<String> serviceUrlOpt = servicesSwaggerInfo.getServiceUrl(route);
RestTemplate restTemplate = getRestTemplate(serviceUrlOpt.isPresent());
UriComponentsBuilder uriBuilder = getServiceUrlBuilder(route, serviceUrlOpt);
String url = uriBuilder.build().toUriString();
String url = getServiceUrlBuilder(route, serviceUrlOpt)
.path(servicesSwaggerInfo.getSwaggerResourcesUrl(route))
.build()
.toUriString();
try {
return restTemplate.exchange(url, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference<List<SwaggerResource>>(){})
.getBody();
} catch (IllegalStateException e) {
log.error("Some unexpected error while requesting swagger resources from: {}", url);
if (e.getMessage() == null || !e.getMessage().startsWith("No instances available for")) {
throw e;
}
throw new NotFoundException();
throw new NotFoundException(e);
}
}

@Override
public ObjectNode getOriginalSwaggerDoc(String route, String group) {
Optional<String> serviceUrlOpt = servicesSwaggerInfo.getServiceUrl(route);
RestTemplate restTemplate = getRestTemplate(serviceUrlOpt.isPresent());
UriComponentsBuilder uriBuilder = getServiceUrlBuilder(route, serviceUrlOpt);
UriComponentsBuilder uriBuilder = getServiceUrlBuilder(route, serviceUrlOpt)
.path(servicesSwaggerInfo.getSwaggerUrl(route));
if (group != null) {
uriBuilder.queryParam("group", group);
}
Expand All @@ -86,8 +90,7 @@ public ObjectNode getOriginalSwaggerDoc(String route, String group) {
if (e.getMessage() == null || !e.getMessage().startsWith("No instances available for")) {
throw e;
}
log.error("Requested resources URL is wrong", e);
throw new NotFoundException();
throw new NotFoundException(e);
}
}

Expand All @@ -101,7 +104,6 @@ private RestTemplate getRestTemplate(boolean isUrlBased) {
private UriComponentsBuilder getServiceUrlBuilder(String route, Optional<String> serviceUrlOpt) {
String serviceUrl = servicesSwaggerInfo.getDirectSwaggerBaseUrl(route)
.orElseGet(() -> serviceUrlOpt.orElseGet(() -> servicesSwaggerInfo.getDefaultProtocol() + route));
return UriComponentsBuilder.fromHttpUrl(serviceUrl)
.path(servicesSwaggerInfo.getSwaggerUrl(route));
return UriComponentsBuilder.fromHttpUrl(serviceUrl);
}
}

0 comments on commit 911880f

Please sign in to comment.