Skip to content

Commit

Permalink
#91 Fixed invalid json input output
Browse files Browse the repository at this point in the history
  • Loading branch information
vityaman committed Apr 30, 2024
1 parent dbe4239 commit 8f0f4c8
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice
import org.springframework.web.server.ServerWebInputException
import ru.vityaman.lms.botalka.app.spring.api.http.server.GeneralErrorMessage

@RestControllerAdvice
Expand Down Expand Up @@ -60,4 +61,18 @@ class DriverExceptionMapping {
),
)
}

@ExceptionHandler(ServerWebInputException::class)
fun handle(exception: ServerWebInputException) = run {
val code = HttpStatus.BAD_REQUEST
ResponseEntity
.status(code)
.body(
GeneralErrorMessage(
code = code.value(),
status = code.reasonPhrase,
message = "Input is invalid: ${exception.reason ?: ""}",
),
)
}
}

0 comments on commit 8f0f4c8

Please sign in to comment.