diff --git a/goofy-server/src/main/java/de/itvsh/goofy/common/user/UserRemoteService.java b/goofy-server/src/main/java/de/itvsh/goofy/common/user/UserRemoteService.java index ddcd94f911108718d4a31d1a0670653d79702833..700057bec12c2287b23a61f4a3d530067d3298b7 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/common/user/UserRemoteService.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/common/user/UserRemoteService.java @@ -86,6 +86,8 @@ public class UserRemoteService { return null; } throw new ServiceUnavailableException(MessageCode.USER_MANAGER_SERVICE_UNAVAILABLE, e); + } catch (IllegalArgumentException e) { + throw new ServiceUnavailableException(MessageCode.USER_MANAGER_SERVICE_UNAVAILABLE, e); } } diff --git a/goofy-server/src/test/java/de/itvsh/goofy/common/user/UserRemoteServiceTest.java b/goofy-server/src/test/java/de/itvsh/goofy/common/user/UserRemoteServiceTest.java index 772b65b2351ab457ad77f86cd1a407ee39c3767a..ef6086164fe2067fd5ba48f64d4ad0658fec63e7 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/common/user/UserRemoteServiceTest.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/common/user/UserRemoteServiceTest.java @@ -200,17 +200,26 @@ class UserRemoteServiceTest { @Nested class TestOnErrorResponse { - private final HttpClientErrorException serviceUnavailableException = new HttpClientErrorException(HttpStatus.SERVICE_UNAVAILABLE, + private final HttpClientErrorException httpClientErrorException = new HttpClientErrorException(HttpStatus.SERVICE_UNAVAILABLE, "Test error"); + private final IllegalArgumentException illegalArgumentException = new IllegalArgumentException(); private final HttpClientErrorException notFoundException = new HttpClientErrorException(HttpStatus.NOT_FOUND, "Test error"); @Test void shouldThrowServiceUnavailablExceptionOnException() { - when(restTemplate.exchange(anyString(), eq(HttpMethod.GET), any(), eq(Object.class))).thenThrow(serviceUnavailableException); + when(restTemplate.exchange(anyString(), eq(HttpMethod.GET), any(), eq(Object.class))).thenThrow(httpClientErrorException); assertThatThrownBy(() -> service.getUser(UserProfileTestFactory.ID)).isInstanceOf(ServiceUnavailableException.class) - .hasCause(serviceUnavailableException); + .hasCause(httpClientErrorException); + } + + @Test + void shouldThrowServiceUnavailablExceptionOnIlleglaArgumentException() { + when(restTemplate.exchange(anyString(), eq(HttpMethod.GET), any(), eq(Object.class))).thenThrow(illegalArgumentException); + + assertThatThrownBy(() -> service.getUser(UserProfileTestFactory.ID)).isInstanceOf(ServiceUnavailableException.class) + .hasCause(illegalArgumentException); } @Test