Skip to content

Commit

Permalink
#91 Catching invalid timestamp at json
Browse files Browse the repository at this point in the history
  • Loading branch information
vityaman committed Apr 30, 2024
1 parent c9de90b commit acd75c1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ru.vityaman.lms.botalka.app.spring.api.http.error

import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.databind.JsonMappingException
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ExceptionHandler
Expand All @@ -23,4 +24,20 @@ class DriverExceptionMapping {
),
)
}

@ExceptionHandler(JsonMappingException::class)
fun handle(exception: JsonMappingException): ResponseEntity<Any> {
val code = HttpStatus.BAD_REQUEST
val offset = exception.location.offsetDescription()
val message = exception.cause!!.message
return ResponseEntity
.status(code)
.body(
GeneralErrorMessage(
code = code.value(),
status = code.reasonPhrase,
message = "Json syntax error at $offset: $message",
),
)
}
}
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: INFO
web: DEBUG
group:
r2dbc: org.springframework.r2dbc,org.springframework.data.r2dbc
management:
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ services:
- GF_SECURITY_ADMIN_PASSWORD=0000
networks:
- lms-network
profiles:
- infra
prometheus:
container_name: lms-prometheus
image: prom/prometheus
Expand All @@ -53,6 +55,8 @@ services:
- ./infra/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
networks:
- lms-network
profiles:
- infra
restler:
container_name: lms-restler
image: restler
Expand Down

0 comments on commit acd75c1

Please sign in to comment.