summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMS <ms@taler.net>2023-09-26 23:07:59 +0200
committerMS <ms@taler.net>2023-09-26 23:07:59 +0200
commit59b5282a9f2aee0f886656f2451234da9962be89 (patch)
tree2666531e0c4a89bb500b4f2aea39e871e46d8673
parentb0a2953609cb0303ea7d071296e87e6e62834112 (diff)
downloadlibeufin-59b5282a9f2aee0f886656f2451234da9962be89.tar.gz
libeufin-59b5282a9f2aee0f886656f2451234da9962be89.tar.bz2
libeufin-59b5282a9f2aee0f886656f2451234da9962be89.zip
Error responses.
Add the 'detail' field to include error messages from the root cause.
-rw-r--r--bank/src/main/kotlin/tech/libeufin/bank/BankMessages.kt3
-rw-r--r--bank/src/main/kotlin/tech/libeufin/bank/Main.kt7
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
index 0ca325f7..d0807f95 100644
--- 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
index eb88d15d..c556b0f2 100644
--- 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
)
)
}