libeufin

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

commit 5e17e49c054d783775e6b7c24e75f9bfc84fabbe
parent f802190b74de0e984058c5da76e4dcf4f575f5ba
Author: MS <ms@taler.net>
Date:   Wed, 27 Jan 2021 15:19:52 +0100

respond 400 on invalid JSON (was 500)

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

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt @@ -22,6 +22,7 @@ package tech.libeufin.nexus.server import com.fasterxml.jackson.core.util.DefaultIndenter import com.fasterxml.jackson.core.util.DefaultPrettyPrinter import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.core.JsonParseException import com.fasterxml.jackson.databind.SerializationFeature import com.fasterxml.jackson.databind.exc.MismatchedInputException import com.fasterxml.jackson.module.kotlin.KotlinModule @@ -137,7 +138,10 @@ suspend inline fun <reified T : Any> ApplicationCall.receiveJson(): T { } catch (e: MissingKotlinParameterException) { throw NexusError(HttpStatusCode.BadRequest, "Missing value for ${e.pathReference}") } catch (e: MismatchedInputException) { - throw NexusError(HttpStatusCode.BadRequest, "Invalid value for ${e.pathReference}") + // Note: POSTing "[]" gets here but e.pathReference is blank. + throw NexusError(HttpStatusCode.BadRequest, "Invalid value for '${e.pathReference}'") + } catch (e: JsonParseException) { + throw NexusError(HttpStatusCode.BadRequest, "Invalid JSON") } }