summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMS <ms@taler.net>2021-01-27 15:19:52 +0100
committerMS <ms@taler.net>2021-01-27 15:19:52 +0100
commit5e17e49c054d783775e6b7c24e75f9bfc84fabbe (patch)
treeb7fe9d16ac116486a862571a8d382c465dd11319
parentf802190b74de0e984058c5da76e4dcf4f575f5ba (diff)
downloadlibeufin-5e17e49c054d783775e6b7c24e75f9bfc84fabbe.tar.gz
libeufin-5e17e49c054d783775e6b7c24e75f9bfc84fabbe.tar.bz2
libeufin-5e17e49c054d783775e6b7c24e75f9bfc84fabbe.zip
respond 400 on invalid JSON (was 500)
-rw-r--r--nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt6
1 files changed, 5 insertions, 1 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
index ef10f006..d8da5fbc 100644
--- 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")
}
}