From 693ef126a8fcf91e532da48ece80d20781806614 Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Mon, 26 Aug 2024 13:34:04 +0200 Subject: [PATCH] [kbss-cvut/fta-fmea-ui#550] Add messageId to the ErrorInfo --- .../controller/util/RestExceptionHandler.java | 25 +++++++++++++++---- .../kbss/analysis/dto/error/ErrorInfo.java | 4 +++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/java/cz/cvut/kbss/analysis/controller/util/RestExceptionHandler.java b/src/main/java/cz/cvut/kbss/analysis/controller/util/RestExceptionHandler.java index 365b9659..b59973ef 100755 --- a/src/main/java/cz/cvut/kbss/analysis/controller/util/RestExceptionHandler.java +++ b/src/main/java/cz/cvut/kbss/analysis/controller/util/RestExceptionHandler.java @@ -24,21 +24,30 @@ public class RestExceptionHandler { @ResponseStatus(HttpStatus.UNAUTHORIZED) public ErrorInfo handleAuthenticationError(HttpServletRequest request, Throwable t) { log.warn("> handleAuthenticationError - {}", request.getRequestURI()); - return new ErrorInfo(t.getMessage(), request.getRequestURI()); + return ErrorInfo.builder() + .message(t.getMessage()) + .requestUri(request.getRequestURI()) + .build(); } @ExceptionHandler(EntityNotFoundException.class) @ResponseStatus(HttpStatus.NOT_FOUND) public ErrorInfo handleNotFoundError(HttpServletRequest request, Throwable t) { log.warn("> handleNotFoundError - {}", request.getRequestURI()); - return new ErrorInfo(t.getMessage(), request.getRequestURI()); + return ErrorInfo.builder() + .message(t.getMessage()) + .requestUri(request.getRequestURI()) + .build(); } @ExceptionHandler(LogicViolationException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public ErrorInfo handleLogicViolationError(HttpServletRequest request, Throwable t) { log.warn("> handleLogicViolationError - {}", request.getRequestURI()); - return new ErrorInfo(t.getMessage(), request.getRequestURI()); + return ErrorInfo.builder() + .message(t.getMessage()) + .requestUri(request.getRequestURI()) + .build(); } @ExceptionHandler(ValidationException.class) @@ -51,13 +60,19 @@ public ErrorInfo handleValidationException(HttpServletRequest request, Validatio .map(DefaultMessageSourceResolvable::getDefaultMessage) .collect(Collectors.joining(",", "[", "]")); - return new ErrorInfo(errorMessage, request.getRequestURI()); + return ErrorInfo.builder() + .message(errorMessage) + .requestUri(request.getRequestURI()) + .build(); } @ExceptionHandler(CalculationException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public ErrorInfo handleEvaluationException(HttpServletRequest request, CalculationException e) { log.warn("> handleEvaluationException - {}", request.getRequestURI()); - return new ErrorInfo(e.getMessage(), request.getRequestURI()); + return ErrorInfo.builder() + .message(e.getMessage()) + .requestUri(request.getRequestURI()) + .build(); } } diff --git a/src/main/java/cz/cvut/kbss/analysis/dto/error/ErrorInfo.java b/src/main/java/cz/cvut/kbss/analysis/dto/error/ErrorInfo.java index 0f051657..b61e22f7 100755 --- a/src/main/java/cz/cvut/kbss/analysis/dto/error/ErrorInfo.java +++ b/src/main/java/cz/cvut/kbss/analysis/dto/error/ErrorInfo.java @@ -1,16 +1,20 @@ package cz.cvut.kbss.analysis.dto.error; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @Data @AllArgsConstructor @NoArgsConstructor +@Builder public class ErrorInfo { private String message; + private String messageId; + private String requestUri; }