From 03140052372250751e3f209a4a4c59aba8d000fc Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 15 Jun 2023 15:09:03 +0200 Subject: [PATCH] SEBSERV-450 better error handling in case of parese error --- .../seb/sebserver/gui/service/page/impl/PageAction.java | 3 +++ .../gui/service/remote/webservice/api/RestCall.java | 6 +++++- .../sebserver/gui/integration/UseCasesIntegrationTest.java | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java index 1c78953e..03149686 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java @@ -185,6 +185,9 @@ public final class PageAction { } catch (final PageMessageException pme) { PageAction.this.pageContext.publishPageMessage(pme); return; + } catch (final Exception e) { + this.pageContext.notifyUnexpectedError(e); + return; } } else { callback.accept(exec()); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java index 8f1dd4c2..483e48cf 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java @@ -180,7 +180,7 @@ public abstract class RestCall { e, "NO RESPONSE AVAILABLE", String.valueOf(builder))); - return Result.ofError(e); + return Result.ofError(restCallError); } } @@ -216,6 +216,10 @@ public abstract class RestCall { } else { restCallError.errors.add(APIMessage.ErrorMessage.GENERIC.of(responseEntity.getBody())); } + } catch (final Exception e) { + final String body = responseEntity.getBody(); + log.error("Failed to parse rest response error message: {}", body); + throw e; } log.debug( diff --git a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java index 6d62f73d..e8d72124 100644 --- a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java @@ -1578,7 +1578,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { fail("Exception expected here"); } catch (final Exception e) { - assertEquals("argument \"content\" is null", e.getMessage()); + assertEquals("Unexpected error while rest call", e.getMessage()); } // test follow-up integrity violation @@ -1596,7 +1596,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { fail("Exception expected here"); } catch (final Exception e) { - assertEquals("argument \"content\" is null", e.getMessage()); + assertEquals("Unexpected error while rest call", e.getMessage()); } final ConfigurationTableValues newTableValue = new ConfigurationTableValues(