Skip to content
Snippets Groups Projects
Commit 9f6ad9b9 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4949 Refactored Exceptionhandling

parent 742ab9c7
No related branches found
No related tags found
No related merge requests found
...@@ -68,10 +68,14 @@ public class ExceptionController extends ResponseEntityExceptionHandler { ...@@ -68,10 +68,14 @@ public class ExceptionController extends ResponseEntityExceptionHandler {
@ExceptionHandler(ConstraintViolationException.class) @ExceptionHandler(ConstraintViolationException.class)
public ErrorResponse handleConstraintViolationException(ConstraintViolationException ex) { 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()))); 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) { private List<Map<String, String>> getDetailedviolationList(Optional<Set<ConstraintViolation<?>>> violations) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment