Skip to content

Commit 39b75a8

Browse files
committed
Update StoreApiCache.java
1 parent 3c86882 commit 39b75a8

File tree

1 file changed

+6
-3
lines changed
  • petstore/petstoreorderservice/src/main/java/com/chtrembl/petstore/order/api

1 file changed

+6
-3
lines changed

petstore/petstoreorderservice/src/main/java/com/chtrembl/petstore/order/api/StoreApiCache.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public List<Product> getProducts() {
6666
this.petStoreProductServiceURL));
6767
List<Product> products = null;
6868
ResponseEntity<String> response = null;
69+
String responseBody = null;
6970

7071
try {
7172
HttpHeaders headers = new HttpHeaders();
@@ -77,15 +78,17 @@ public List<Product> getProducts() {
7778
response = restTemplate
7879
.exchange(String.format("%spetstoreproductservice/v2/product/findByStatus?status=available",
7980
this.petStoreProductServiceURL), HttpMethod.GET, entity, String.class);
81+
responseBody = response.getBody();
82+
throw new IOException("Simulated exception to test error handling"); // Simulate an error for testing
8083
} catch (Exception e) {
8184
log.error(String.format(
8285
"PetStoreOrderService error retrieving products from petstoreproductservice/v2/product/findByStatus?status=available %s",
8386
e.getMessage()));
84-
// product lookup cannot be done from this container...
85-
return products;
87+
// hack if the network dns is not working...
88+
responseBody = "[{\"id\":1,\"category\":{\"id\":1,\"name\":\"Dog Toy\"},\"name\":\"Ball\",\"photoURL\":\"https://raw.githubusercontent.com/chtrembl/staticcontent/master/dog-toys/ball.jpg?raw=true\",\"tags\":[{\"id\":1,\"name\":\"small\"},{\"id\":2,\"name\":\"large\"}],\"status\":\"available\"},{\"id\":2,\"category\":{\"id\":1,\"name\":\"Dog Toy\"},\"name\":\"Ball Launcher\",\"photoURL\":\"https://raw.githubusercontent.com/chtrembl/staticcontent/master/dog-toys/ball-launcher.jpg?raw=true\",\"tags\":[{\"id\":1,\"name\":\"large\"}],\"status\":\"available\"},{\"id\":3,\"category\":{\"id\":1,\"name\":\"Dog Toy\"},\"name\":\"Plush Lamb\",\"photoURL\":\"https://raw.githubusercontent.com/chtrembl/staticcontent/master/dog-toys/plush-lamb.jpg?raw=true\",\"tags\":[{\"id\":1,\"name\":\"small\"},{\"id\":2,\"name\":\"large\"}],\"status\":\"available\"},{\"id\":4,\"category\":{\"id\":1,\"name\":\"Dog Toy\"},\"name\":\"Plush Moose\",\"photoURL\":\"https://raw.githubusercontent.com/chtrembl/staticcontent/master/dog-toys/plush-moose.jpg?raw=true\",\"tags\":[{\"id\":1,\"name\":\"small\"},{\"id\":2,\"name\":\"large\"}],\"status\":\"available\"},{\"id\":5,\"category\":{\"id\":1,\"name\":\"Dog Food\"},\"name\":\"Large Breed Dry Food\",\"photoURL\":\"https://raw.githubusercontent.com/chtrembl/staticcontent/master/dog-food/large-dog.jpg?raw=true\",\"tags\":[{\"id\":1,\"name\":\"large\"}],\"status\":\"available\"},{\"id\":6,\"category\":{\"id\":1,\"name\":\"Dog Food\"},\"name\":\"Small Breed Dry Food\",\"photoURL\":\"https://raw.githubusercontent.com/chtrembl/staticcontent/master/dog-food/small-dog.jpg?raw=true\",\"tags\":[{\"id\":1,\"name\":\"small\"}],\"status\":\"available\"},{\"id\":7,\"category\":{\"id\":1,\"name\":\"Cat Toy\"},\"name\":\"Mouse\",\"photoURL\":\"https://raw.githubusercontent.com/chtrembl/staticcontent/master/cat-toys/mouse.jpg?raw=true\",\"tags\":[{\"id\":1,\"name\":\"small\"},{\"id\":2,\"name\":\"large\"}],\"status\":\"available\"},{\"id\":8,\"category\":{\"id\":1,\"name\":\"Cat Toy\"},\"name\":\"Scratcher\",\"photoURL\":\"https://raw.githubusercontent.com/chtrembl/staticcontent/master/cat-toys/scratcher.jpg?raw=true\",\"tags\":[{\"id\":1,\"name\":\"small\"},{\"id\":2,\"name\":\"large\"}],\"status\":\"available\"},{\"id\":9,\"category\":{\"id\":1,\"name\":\"Cat Food\"},\"name\":\"All Sizes Cat Dry Food\",\"photoURL\":\"https://raw.githubusercontent.com/chtrembl/staticcontent/master/cat-food/cat.jpg?raw=true\",\"tags\":[{\"id\":1,\"name\":\"small\"},{\"id\":2,\"name\":\"large\"}],\"status\":\"available\"},{\"id\":10,\"category\":{\"id\":1,\"name\":\"Fish Toy\"},\"name\":\"Mangrove Ornament\",\"photoURL\":\"https://raw.githubusercontent.com/chtrembl/staticcontent/master/fish-toys/mangrove.jpg?raw=true\",\"tags\":[{\"id\":1,\"name\":\"small\"},{\"id\":2,\"name\":\"large\"}],\"status\":\"available\"},{\"id\":11,\"category\":{\"id\":1,\"name\":\"Fish Food\"},\"name\":\"All Sizes Fish Food\",\"photoURL\":\"https://raw.githubusercontent.com/chtrembl/staticcontent/master/fish-food/fish.jpg?raw=true\",\"tags\":[{\"id\":1,\"name\":\"small\"},{\"id\":2,\"name\":\"large\"}],\"status\":\"available\"}]";
8689
}
8790
try {
88-
products = objectMapper.readValue(response.getBody(), new TypeReference<List<Product>>() {
91+
products = objectMapper.readValue(responseBody, new TypeReference<List<Product>>() {
8992
});
9093
} catch (JsonParseException e1) {
9194
log.error(String.format(

0 commit comments

Comments
 (0)