From 57aef9f572b8b6952473f2eed2156b3b97bb718a Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Mon, 21 Nov 2022 09:39:55 +0100
Subject: [PATCH] OZG-2966 OZG-3171 catch IllegalArgumentException

---
 .../goofy/common/user/UserRemoteService.java      |  2 ++
 .../goofy/common/user/UserRemoteServiceTest.java  | 15 ++++++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

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 ddcd94f911..700057bec1 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 772b65b235..ef6086164f 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
-- 
GitLab