From 9f6ad9b9ddbe709f534091851339174055ac8c2b Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Thu, 29 Feb 2024 11:36:19 +0100
Subject: [PATCH] OZG-4949 Refactored Exceptionhandling

---
 .../admin/common/errorhandling/ExceptionController.java   | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/main/java/de/ozgcloud/admin/common/errorhandling/ExceptionController.java b/src/main/java/de/ozgcloud/admin/common/errorhandling/ExceptionController.java
index 6ef99942..f4c64671 100644
--- a/src/main/java/de/ozgcloud/admin/common/errorhandling/ExceptionController.java
+++ b/src/main/java/de/ozgcloud/admin/common/errorhandling/ExceptionController.java
@@ -68,10 +68,14 @@ public class ExceptionController extends ResponseEntityExceptionHandler {
 
 	@ExceptionHandler(ConstraintViolationException.class)
 	public ErrorResponse handleConstraintViolationException(ConstraintViolationException ex) {
-		var problemDetail = ProblemDetail.forStatusAndDetail(HttpStatus.UNPROCESSABLE_ENTITY, ex.getLocalizedMessage());
+		var problemDetail = buildProblemDetail(HttpStatus.UNPROCESSABLE_ENTITY, ex);
+		return ErrorResponse.builder(ex, problemDetail).build();
+	}
 
+	private ProblemDetail buildProblemDetail(HttpStatus status, ConstraintViolationException ex) {
+		var problemDetail = ProblemDetail.forStatusAndDetail(status, ex.getLocalizedMessage());
 		problemDetail.setProperty("invalid-params", getDetailedviolationList(Optional.ofNullable(ex.getConstraintViolations())));
-		return ErrorResponse.builder(ex, problemDetail).build();
+		return problemDetail;
 	}
 
 	private List<Map<String, String>> getDetailedviolationList(Optional<Set<ConstraintViolation<?>>> violations) {
-- 
GitLab