-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validation 체크 및 ControllerExceptionAdvice 생성
- Loading branch information
1 parent
4239842
commit e38b6f6
Showing
7 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
bbaemin-api/src/main/java/org/bbaemin/config/advice/ControllerExceptionAdvice.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.bbaemin.config.advice; | ||
|
||
import org.bbaemin.config.exception.BindException; | ||
import org.bbaemin.config.response.ApiResult; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.validation.FieldError; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import java.util.List; | ||
|
||
@RestControllerAdvice | ||
public class ControllerExceptionAdvice { | ||
|
||
@ExceptionHandler(BindException.class) | ||
public ApiResult<?> handleBindException(BindException e) { | ||
BindingResult bindingResult = e.getBindingResult(); | ||
List<FieldError> fieldErrors = bindingResult.getFieldErrors(); | ||
return ApiResult.badRequest(fieldErrors); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
bbaemin-api/src/main/java/org/bbaemin/config/exception/BindException.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.bbaemin.config.exception; | ||
|
||
import lombok.Getter; | ||
import org.springframework.validation.BindingResult; | ||
|
||
@Getter | ||
public class BindException extends RuntimeException { | ||
|
||
private BindingResult bindingResult; | ||
|
||
public BindException(BindingResult bindingResult) { | ||
this.bindingResult = bindingResult; | ||
} | ||
} |
This file contains 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 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 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 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 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