Skip to content
Snippets Groups Projects
Commit 96010c66 authored by Jakub Janeček's avatar Jakub Janeček
Browse files

Fix 404 of other services

parent 5f648776
No related branches found
No related tags found
No related merge requests found
Pipeline #95003 passed
......@@ -8,6 +8,7 @@ import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import java.util.Optional;
......@@ -25,15 +26,20 @@ public class OddsClient {
}
String baseUrl = instance.getUri().toString();
var oddsDto = webClientBuilder
.baseUrl(baseUrl)
.build()
.get()
.uri("/odds/{id}", id)
.retrieve()
.bodyToMono(OddsDto.class)
.block();
return oddsDto != null ? Optional.of(OddsConverter.toModel(oddsDto)) : Optional.empty();
try {
var oddsDto = webClientBuilder
.baseUrl(baseUrl)
.build()
.get()
.uri("/odds/{id}", id)
.retrieve()
.bodyToMono(OddsDto.class)
.block();
return Optional.of(OddsConverter.toModel(oddsDto));
} catch (WebClientResponseException.NotFound e) {
return Optional.empty();
} catch (Exception e) {
return Optional.empty();
}
}
}
......@@ -8,6 +8,7 @@ import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import java.util.Optional;
......@@ -25,15 +26,20 @@ public class UserClient {
}
String baseUrl = instance.getUri().toString();
var userDto = webClientBuilder
.baseUrl(baseUrl)
.build()
.get()
.uri("/users/{id}", id)
.retrieve()
.bodyToMono(UserDto.class)
.block();
return userDto != null ? Optional.of(UserConverter.toModel(userDto)) : Optional.empty();
try {
var userDto = webClientBuilder
.baseUrl(baseUrl)
.build()
.get()
.uri("/users/{id}", id)
.retrieve()
.bodyToMono(UserDto.class)
.block();
return Optional.of(UserConverter.toModel(userDto));
} catch (WebClientResponseException.NotFound e) {
return Optional.empty();
} catch (Exception e) {
return Optional.empty();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment