diff --git a/src/main/java/ohm/softa/a11/App.java b/src/main/java/ohm/softa/a11/App.java index 8639757b9100226a90a165e23bf01faf4f33a4ce..b9e4e564465a7a3603667d62ab700f7d4bf9c138 100644 --- a/src/main/java/ohm/softa/a11/App.java +++ b/src/main/java/ohm/softa/a11/App.java @@ -4,6 +4,7 @@ import ohm.softa.a11.openmensa.OpenMensaAPI; import ohm.softa.a11.openmensa.OpenMensaAPIService; import ohm.softa.a11.openmensa.model.Canteen; import ohm.softa.a11.openmensa.model.PageInfo; +import retrofit2.HttpException; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -109,6 +110,21 @@ public class App { /* TODO fetch all meals for the currently selected canteen * to avoid errors retrieve at first the state of the canteen and check if the canteen is opened at the selected day * don't forget to check if a canteen was selected previously! */ + if (currentCanteenId == -1) { + System.out.println("Error: no canteen selected"); + return; + } + + openMensaAPI + .getMeals(currentCanteenId, dateFormat.format(currentDate.getTime())) + .exceptionally((e) -> { + System.out.println(e.getMessage()); + if (e instanceof HttpException) System.out.println(((HttpException) e).response()); + return List.of(); + }) + .thenAccept(meals -> meals.forEach(System.out::println)) + .join(); + } /**