Skip to content

Commit

Permalink
#77 Response with GeneralError on json syntax error (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
vityaman authored Apr 24, 2024
1 parent 579a52c commit 27a6ffa
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.vityaman.lms.botalka.api.http.error

import com.fasterxml.jackson.core.JsonParseException
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 ru.vityaman.lms.botalka.api.http.server.GeneralErrorMessage

@RestControllerAdvice
class DriverExceptionMapping {
@ExceptionHandler(JsonParseException::class)
fun handle(exception: JsonParseException): ResponseEntity<Any> {
val code = HttpStatus.BAD_REQUEST
val offset = exception.location.offsetDescription()
return ResponseEntity
.status(code)
.body(
GeneralErrorMessage(
code = code.value(),
status = code.reasonPhrase,
message = "Json syntax error at $offset",
),
)
}
}

0 comments on commit 27a6ffa

Please sign in to comment.