Skip to content

Commit

Permalink
[kbss-cvut/fta-fmea-ui#550] Add messageId to the ErrorInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan committed Aug 26, 2024
1 parent 340420a commit 693ef12
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
}
}
4 changes: 4 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/dto/error/ErrorInfo.java
Original file line number Diff line number Diff line change
@@ -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;

}

0 comments on commit 693ef12

Please sign in to comment.