diff options
author | ms <ms@taler.net> | 2021-09-22 08:37:44 +0200 |
---|---|---|
committer | ms <ms@taler.net> | 2021-09-22 08:37:44 +0200 |
commit | 197996d952573f0103567c4e5b33ba53b1a316cb (patch) | |
tree | 8b353eedf605362b711582bcffaca182f2ba528e /sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt | |
parent | 91cad84591efd36aa685b18ae2ba9939afb1a6f1 (diff) | |
download | libeufin-197996d952573f0103567c4e5b33ba53b1a316cb.tar.gz libeufin-197996d952573f0103567c4e5b33ba53b1a316cb.tar.bz2 libeufin-197996d952573f0103567c4e5b33ba53b1a316cb.zip |
more error codes
Diffstat (limited to 'sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt')
-rw-r--r-- | sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt index e42cc251..0a432451 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt @@ -1,6 +1,7 @@ package tech.libeufin.sandbox import io.ktor.http.* +import org.apache.http.HttpStatus import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.transactions.transaction import org.slf4j.Logger @@ -143,8 +144,18 @@ fun wireTransfer( } catch (e: Exception) { throw SandboxError(HttpStatusCode.BadRequest, "Amount given not valid: $amount") } + // Extra check on the currency's consistency + if (credit.currency != debit.currency) throw SandboxError( + HttpStatusCode.InternalServerError, + "Credit and debit account have different currency (${credit.currency} vs ${debit.currency})!", + LibeufinErrorCode.LIBEUFIN_EC_CURRENCY_INCONSISTENT + ) if (amountObj.currency != credit.currency || amountObj.currency != debit.currency) { - throw SandboxError(HttpStatusCode.BadRequest, "currency (${amountObj.currency}) can't be accepted") + throw SandboxError( + HttpStatusCode.BadRequest, + "Currency (${amountObj.currency}) is not supported", + LibeufinErrorCode.LIBEUFIN_EC_BAD_CURRENCY + ) } val randId = getRandomString(16) BankAccountTransactionEntity.new { |