@@ -43,8 +43,8 @@ class ErrorAttributes : DefaultErrorAttributes() {
4343 override fun getErrorAttributes (webRequest : WebRequest , includeStackTrace : Boolean ): Map <String , Any ?> {
4444 val attrs = super .getErrorAttributes(webRequest, false )
4545 return mapOf (
46- " exception" to attrs.get( " error" ) ,
47- " details" to attrs.get( " message" ) )
46+ " exception" to attrs[ " error" ] ,
47+ " details" to attrs[ " message" ] )
4848 }
4949}
5050
@@ -99,20 +99,23 @@ class GlobalControllerExceptionHandler : ResponseEntityExceptionHandler() {
9999
100100 fun List<ObjectError>.body (): ExceptionBody = ExceptionBody (
101101 exception = WrongParamsException ::class .simpleName.toString(),
102- details = this .associateBy({ (it as FieldError ).getField() }, { it.defaultMessage })
102+ details = this .associateBy({ (it as FieldError ).field }, { it.defaultMessage })
103103 )
104104
105105 fun DataIntegrityViolationException.body (): ExceptionBody =
106106 (this .cause as ? ConstraintViolationException )?.sqlException?.let {
107107 val sqlMsg = it.message ? : " "
108- val (name, msg) =
109- if (" foreign key constraint fails" in sqlMsg) {
110- " ForeignKeyException" to " A field references a non-existing resource."
111- } else if (" Duplicate entry" in sqlMsg) {
112- " DuplicateFieldException" to " value ${sqlMsg.split(" " )[2 ]} already exists."
113- } else {
114- " SqlException" to sqlMsg
115- }
108+ val (name, msg) = when {
109+ " foreign key constraint fails" in sqlMsg -> {
110+ " ForeignKeyException" to " A field references a non-existing resource."
111+ }
112+ " Duplicate entry" in sqlMsg -> {
113+ " DuplicateFieldException" to " value ${sqlMsg.split(" " )[2 ]} already exists."
114+ }
115+ else -> {
116+ " SqlException" to sqlMsg
117+ }
118+ }
116119 ExceptionBody (name, msg)
117120 } ? : ExceptionBody .fromThrowable(this )
118121 }
0 commit comments