-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
35 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
simtong-infrastructure/src/main/kotlin/team/comit/simtong/global/error/CustomFieldError.kt
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,36 @@ | ||
package team.comit.simtong.global.error | ||
|
||
import org.springframework.validation.BindingResult | ||
|
||
/** | ||
* | ||
* 상세한 예외를 보여주기 위한 CustomFieldError | ||
* | ||
* @author kimbeomjin | ||
* @date 2022/09/07 | ||
* @version 1.0.0 | ||
**/ | ||
class CustomFieldError( | ||
val field: String, | ||
val value: String, | ||
val reason: String | ||
) { | ||
companion object { | ||
fun of(field: String, value: String, reason: String): List<CustomFieldError> { | ||
val fieldErrors: MutableList<CustomFieldError> = ArrayList() | ||
fieldErrors.add(CustomFieldError(field, value, reason)) | ||
return fieldErrors | ||
} | ||
|
||
fun of(bindingResult: BindingResult): List<CustomFieldError> { | ||
val fieldErrors = bindingResult.fieldErrors | ||
return fieldErrors.map { error -> | ||
CustomFieldError( | ||
field = error.field, | ||
value = error.rejectedValue.toString(), | ||
reason = error.defaultMessage!! | ||
) | ||
} | ||
} | ||
} | ||
} |
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