Skip to content

Commit

Permalink
fix: sonarCloud 에러 수정 (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
choidongkuen committed Jan 22, 2024
1 parent 3806247 commit 88dda97
Showing 1 changed file with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,15 @@ public UserAroundLocationsResponse getUserAroundLocations(
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(IllegalArgumentException.class)
public ErrorResponse handleIllegalArgumentException(IllegalArgumentException illegalArgumentException) {
Sentry.captureException(illegalArgumentException);
return ErrorResponse.of(illegalArgumentException);
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MethodArgumentNotValidException.class)
public ErrorResponse handleMethodArgumentNotValidException(
MethodArgumentNotValidException methodArgumentNotValidException) {
Sentry.captureException(methodArgumentNotValidException);

BindingResult bindingResult = methodArgumentNotValidException.getBindingResult();
List<ObjectError> errors = bindingResult.getAllErrors();

return ErrorResponse.of(errors.get(0).getDefaultMessage());
@ExceptionHandler({IllegalArgumentException.class, MethodArgumentNotValidException.class})
public ErrorResponse handleException(Exception exception) {
Sentry.captureException(exception);
if (exception instanceof MethodArgumentNotValidException methodArgumentNotValidException) {
BindingResult bindingResult = methodArgumentNotValidException.getBindingResult();
List<ObjectError> errors = bindingResult.getAllErrors();
return ErrorResponse.of(errors.get(0).getDefaultMessage());
} else {
return ErrorResponse.of(exception);
}
}
}

0 comments on commit 88dda97

Please sign in to comment.