libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit 8426fc73752b00fe6bebc6fcac359346225370cd
parent 0376eecc51832a2413acbdb122eaa4175ecf0382
Author: MS <ms@taler.net>
Date:   Sun, 15 Aug 2021 23:45:32 -1100

Global handler for invalid POSTed data.

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt | 12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -25,6 +25,7 @@ import com.fasterxml.jackson.core.util.DefaultPrettyPrinter import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.core.JsonParseException import com.fasterxml.jackson.databind.DeserializationFeature +import com.fasterxml.jackson.databind.JsonMappingException import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.databind.exc.MismatchedInputException import com.fasterxml.jackson.module.kotlin.KotlinModule @@ -197,6 +198,17 @@ fun serverMain(host: String, port: Int) { ) ) } + exception<JsonMappingException> { cause -> + logger.error("Exception while handling '${call.request.uri}'", cause) + call.respond( + HttpStatusCode.BadRequest, + message = ErrorResponse( + code = TalerErrorCode.TALER_EC_GENERIC_JSON_INVALID.code, + hint = "POSTed data was not valid", + detail = cause.message ?: "not given", + ) + ) + } exception<UtilError> { cause -> logger.error("Exception while handling '${call.request.uri}'", cause) call.respond(