response.body instead of statuscode and return full recipe

This commit is contained in:
Mei Chang van der Werff 2025-11-28 21:18:03 +01:00
commit 8be89e1863

View file

@ -41,7 +41,7 @@ public class ServerUtils {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if(response.statusCode() != statusOK){ if(response.statusCode() != statusOK){
throw new IOException("No recipe to get. Server responds with " + response.statusCode()); throw new IOException("No recipe to get. Server responds with " + response.body());
} }
@ -62,7 +62,7 @@ public class ServerUtils {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if(response.statusCode() != statusOK){ if(response.statusCode() != statusOK){
throw new IOException("failed finding recipe with id: "+ id + " body: " + response.statusCode()); throw new IOException("failed finding recipe with id: "+ id + " body: " + response.body());
} }
return objectMapper.readValue(response.body(),Recipe.class); return objectMapper.readValue(response.body(),Recipe.class);
@ -96,7 +96,7 @@ public class ServerUtils {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if(response.statusCode() != statusOK){ if(response.statusCode() != statusOK){
throw new IOException("Failed to add Recipe: " + newRecipe.getId() + "body: " + response.statusCode()); throw new IOException("Failed to add Recipe: " + newRecipe.toDetailedString() + "body: " + response.body());
} }
return objectMapper.readValue(response.body(),Recipe.class); return objectMapper.readValue(response.body(),Recipe.class);
@ -114,7 +114,7 @@ public class ServerUtils {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if(response.statusCode() != statusOK){ if(response.statusCode() != statusOK){
throw new IOException("Failed removing recipe with id: " + id + "body: " + response.statusCode()); throw new IOException("Failed removing recipe with id: " + id + "body: " + response.body());
} }
} }
@ -133,7 +133,7 @@ public class ServerUtils {
//200 is the status code for success, other codes can mean there is no recipe to clone //200 is the status code for success, other codes can mean there is no recipe to clone
if(response.statusCode() != statusOK){ if(response.statusCode() != statusOK){
throw new IOException("Failed to get recipe to clone with id: " + id + "body: " + response.statusCode()); throw new IOException("Failed to get recipe to clone with id: " + id + "body: " + response.body());
} }
// recipe exists so you can make a "new" recipe aka the clone // recipe exists so you can make a "new" recipe aka the clone
Recipe recipe = objectMapper.readValue(response.body(), Recipe.class); Recipe recipe = objectMapper.readValue(response.body(), Recipe.class);