-
Notifications
You must be signed in to change notification settings - Fork 2
fix: 로그인 중복 검사 시 login패턴 검증하도록 변경 #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| package life.mosu.mosuserver.global.exception; | ||
|
|
||
| import jakarta.persistence.EntityNotFoundException; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.validation.ConstraintViolation; | ||
| import jakarta.validation.ConstraintViolationException; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
| import life.mosu.mosuserver.infra.notify.NotifyClientAdapter; | ||
| import life.mosu.mosuserver.infra.notify.dto.discord.DiscordExceptionNotifyEventRequest; | ||
|
|
@@ -16,6 +18,7 @@ | |
| import org.springframework.web.bind.MethodArgumentNotValidException; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
| import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
| import org.springframework.web.method.annotation.HandlerMethodValidationException; | ||
| import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; | ||
| import org.springframework.web.reactive.resource.NoResourceFoundException; | ||
|
|
||
|
|
@@ -126,7 +129,7 @@ public ResponseEntity<ErrorResponse> handleHttpMessageNotReadableException( | |
| return ResponseEntity.status(HttpStatus.CONFLICT).body(response); | ||
| } | ||
|
|
||
| @ExceptionHandler(NoResourceFoundException.class ) | ||
| @ExceptionHandler(NoResourceFoundException.class) | ||
| public ResponseEntity<ErrorResponse> handleNotFound(Exception ex) { | ||
| notifyIfNeeded(ex); | ||
|
|
||
|
|
@@ -140,12 +143,40 @@ public ResponseEntity<ErrorResponse> handleNotFound(Exception ex) { | |
| } | ||
|
|
||
| @ExceptionHandler(MethodArgumentTypeMismatchException.class) | ||
| public ResponseEntity<ErrorResponse> handleTypeMismatch(MethodArgumentTypeMismatchException ex) { | ||
| public ResponseEntity<ErrorResponse> handleTypeMismatch( | ||
| MethodArgumentTypeMismatchException ex) { | ||
| notifyIfNeeded(ex); | ||
| ErrorResponse response = ErrorResponse.builder() | ||
| .status(HttpStatus.BAD_REQUEST.value()) | ||
| .code("TYPE_MISMATCH") | ||
| .message("요청 파라미터 타입이 올바르지 않습니다.") | ||
| .message(ex.getMessage().toLowerCase(Locale.ROOT)) | ||
| .build(); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); | ||
| } | ||
|
|
||
| @ExceptionHandler(HandlerMethodValidationException.class) | ||
| public ResponseEntity<?> handleHandlerMethodValidation(HandlerMethodValidationException ex) { | ||
| notifyIfNeeded(ex); | ||
| ErrorResponse response = ErrorResponse.builder() | ||
| .status(HttpStatus.BAD_REQUEST.value()) | ||
| .code("TYPE_MISMATCH") | ||
| .message(ex.getMessage().toLowerCase(Locale.ROOT)) | ||
| .build(); | ||
| return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); | ||
| } | ||
|
|
||
| @ExceptionHandler(ConstraintViolationException.class) | ||
| public ResponseEntity<?> handleConstraintViolation(ConstraintViolationException ex) { | ||
| notifyIfNeeded(ex); | ||
| String message = ex.getConstraintViolations().stream() | ||
| .map(ConstraintViolation::getMessage) | ||
| .findFirst() | ||
| .orElse("유효성 검사에 실패했습니다."); | ||
| ErrorResponse response = ErrorResponse.builder() | ||
| .status(HttpStatus.BAD_REQUEST.value()) | ||
| .code("VAILDATION_ERROR") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| .message(message) | ||
| .build(); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exception handler for
HandlerMethodValidationExceptionhas a couple of issues:"TYPE_MISMATCH", which is incorrect for a validation error. It should be"VALIDATION_ERROR"to be consistent with other validation-related handlers.ex.getMessage()for the error message can expose internal implementation details to the client, which is not ideal. It's better to extract just the validation message, similar to how it's done inhandleConstraintViolation.Here's a suggested improvement to extract a clean message and use the correct error code. You might need to add an import for
org.springframework.context.MessageSourceResolvableif it's not already present.