libeufin

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

commit 70b95e9aee7d84d835cc25dd512a24d16604f63b
parent 50b77e32a615a76b06d2d77d4117bd506f69542e
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date:   Mon,  9 Mar 2020 15:44:13 +0100

Capture status code from error object.

Diffstat:
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -83,7 +83,8 @@ fun testData() { } } -data class NexusError(val statusCode: HttpStatusCode, val reason: String) : Exception(reason) +data class NexusError(val statusCode: HttpStatusCode, val reason: String) : Exception() + val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus") @@ -300,9 +301,13 @@ fun main() { } } install(StatusPages) { - exception<Throwable> { cause -> + exception<NexusError> { cause -> logger.error("Exception while handling '${call.request.uri}'", cause) - call.respondText("Internal server error.\n", ContentType.Text.Plain, HttpStatusCode.InternalServerError) + call.respondText( + cause.reason, + ContentType.Text.Plain, + cause.statusCode + ) } exception<javax.xml.bind.UnmarshalException> { cause ->