libeufin

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

commit 59b5282a9f2aee0f886656f2451234da9962be89
parent b0a2953609cb0303ea7d071296e87e6e62834112
Author: MS <ms@taler.net>
Date:   Tue, 26 Sep 2023 23:07:59 +0200

Error responses.

Add the 'detail' field to include error messages from
the root cause.

Diffstat:
Mbank/src/main/kotlin/tech/libeufin/bank/BankMessages.kt | 3++-
Mbank/src/main/kotlin/tech/libeufin/bank/Main.kt | 7++++---
2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/bank/src/main/kotlin/tech/libeufin/bank/BankMessages.kt b/bank/src/main/kotlin/tech/libeufin/bank/BankMessages.kt @@ -70,7 +70,8 @@ data class TokenSuccessResponse( @Serializable data class TalerError( val code: Int, - val hint: String? = null + val hint: String? = null, + val detail: String? = null ) /* Contains contact data to send TAN challges to the diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt @@ -261,13 +261,13 @@ fun Application.corebankWebApp(db: Database, ctx: BankApplicationContext) { * to get the most detailed message, we must consider BOTH sides: * the 'cause' AND its root cause! */ + logger.error(cause.message) var rootCause: Throwable? = cause.cause while (rootCause?.cause != null) rootCause = rootCause.cause /* Here getting _some_ error message, by giving precedence * to the root cause, as otherwise JSON details would be lost. */ - val errorMessage: String? = rootCause?.message ?: cause.message - logger.error(errorMessage) + logger.error(rootCause?.message) // Telling apart invalid JSON vs missing parameter vs invalid parameter. val talerErrorCode = when (cause) { is MissingRequestParameterException -> @@ -282,7 +282,8 @@ fun Application.corebankWebApp(db: Database, ctx: BankApplicationContext) { status = HttpStatusCode.BadRequest, message = TalerError( code = talerErrorCode.code, - hint = errorMessage + hint = cause.message, + detail = rootCause?.message ) ) }