Skip to content

Commit

Permalink
#91 Fixed exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vityaman committed Apr 30, 2024
1 parent 285a0b7 commit c9ea84b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,37 @@ class DriverExceptionMapping {
)
}

@ExceptionHandler(MismatchedInputException::class)
fun handle(exception: MismatchedInputException): ResponseEntity<Any> {
@ExceptionHandler(JsonMappingException::class)
fun handle(exception: JsonMappingException): ResponseEntity<Any> {
val code = HttpStatus.BAD_REQUEST
val offset = exception.location.offsetDescription()
val message = buildString {
append("Json mismatched input error at $offset, ")
append("ensure that all required fields are set")
}
val offset = exception.location?.offsetDescription() ?: "(?, ?)"
val cause = exception.cause?.message ?: "unknown cause"
return ResponseEntity
.status(code)
.body(
GeneralErrorMessage(
code = code.value(),
status = code.reasonPhrase,
message = message,
message = "Json mapping error at $offset: $cause",
),
)
}

@ExceptionHandler(JsonMappingException::class)
fun handle(exception: JsonMappingException): ResponseEntity<Any> {
@ExceptionHandler(MismatchedInputException::class)
fun handle(exception: MismatchedInputException): ResponseEntity<Any> {
val code = HttpStatus.BAD_REQUEST
val offset = exception.location.offsetDescription()
val cause = exception.cause?.message ?: "unknown cause"
val offset = exception.location?.offsetDescription() ?: "(?, ?)"
val message = buildString {
append("Json mismatched input error at $offset, ")
append("ensure that all required fields are set")
}
return ResponseEntity
.status(code)
.body(
GeneralErrorMessage(
code = code.value(),
status = code.reasonPhrase,
message = "Json mapping error at $offset: $cause",
message = message,
),
)
}
Expand Down
2 changes: 1 addition & 1 deletion botalka/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ logging:
root: INFO
r2dbc: INFO
sql: INFO
web: DEBUG
web: INFO
group:
r2dbc: org.springframework.r2dbc,org.springframework.data.r2dbc
management:
Expand Down

0 comments on commit c9ea84b

Please sign in to comment.