From 3a67e48ab03982dbb4b7106e90028ffd115dbc45 Mon Sep 17 00:00:00 2001 From: Hubert Van De Walle Date: Tue, 21 Apr 2020 16:30:55 +0200 Subject: [PATCH] Quick fix to handle bad requests --- api/src/features/ErrorFeature.kt | 17 +++++++++++++++++ api/src/features/Features.kt | 1 + 2 files changed, 18 insertions(+) create mode 100644 api/src/features/ErrorFeature.kt diff --git a/api/src/features/ErrorFeature.kt b/api/src/features/ErrorFeature.kt new file mode 100644 index 0000000..c085ab2 --- /dev/null +++ b/api/src/features/ErrorFeature.kt @@ -0,0 +1,17 @@ +package be.vandewalleh.features + +import io.ktor.application.Application +import io.ktor.application.call +import io.ktor.application.install +import io.ktor.features.StatusPages +import io.ktor.http.HttpStatusCode +import io.ktor.response.respond +import io.ktor.utils.io.errors.IOException + +fun Application.handleErrors() { + install(StatusPages) { + exception { _ -> + call.respond(HttpStatusCode.BadRequest) + } + } +} \ No newline at end of file diff --git a/api/src/features/Features.kt b/api/src/features/Features.kt index 97d1960..09e5942 100644 --- a/api/src/features/Features.kt +++ b/api/src/features/Features.kt @@ -7,4 +7,5 @@ fun Application.features() { corsFeature() contentNegotiationFeature() authenticationModule() + handleErrors() }