commit baf3f567a3cd5551669ff29d28ef72520cea5966
parent 669e4e5b05fc5e4085e0a3f76f46ef2c7493ab08
Author: MS <ms@taler.net>
Date: Mon, 6 Sep 2021 10:16:55 +0000
Define LibEuFin error codes.
Diffstat:
4 files changed, 63 insertions(+), 6 deletions(-)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/EbicsProtocolBackend.kt
@@ -525,10 +525,12 @@ private fun constructCamtResponse(
}
getLastBalance(bankAccount) // last reported balance
}
+
val freshBalance = balanceForAccount(
history = history,
baseBalance = lastBalance
)
+
return listOf(
buildCamtString(
type,
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -84,7 +84,11 @@ import kotlin.system.exitProcess
const val SANDBOX_DB_ENV_VAR_NAME = "LIBEUFIN_SANDBOX_DB_CONNECTION"
private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.sandbox")
-data class SandboxError(val statusCode: HttpStatusCode, val reason: String) : Exception()
+data class SandboxError(
+ val statusCode: HttpStatusCode,
+ val reason: String,
+ val errorCode: LibeufinErrorCode? = null) : Exception()
+
data class SandboxErrorJson(val error: SandboxErrorDetailJson)
data class SandboxErrorDetailJson(val type: String, val description: String)
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/bankAccount.kt
@@ -5,10 +5,7 @@ import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.transactions.transaction
import org.slf4j.Logger
import org.slf4j.LoggerFactory
-import tech.libeufin.util.RawPayment
-import tech.libeufin.util.importDateFromMillis
-import tech.libeufin.util.parseDecimal
-import tech.libeufin.util.toDashedDate
+import tech.libeufin.util.*
import java.math.BigDecimal
private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.sandbox")
@@ -43,7 +40,8 @@ fun balanceForAccount(
}
throw SandboxError(
HttpStatusCode.InternalServerError,
- "A payment direction was found neither CRDT nor DBIT"
+ "A payment direction was found neither CRDT nor DBIT",
+ LibeufinErrorCode.LIBEUFIN_EC_INVALID_STATE
)
}
return ret
diff --git a/util/src/main/kotlin/LibeufinErrorCodes.kt b/util/src/main/kotlin/LibeufinErrorCodes.kt
@@ -0,0 +1,52 @@
+/*
+ This file is part of GNU Taler
+ Copyright (C) 2012-2020 Taler Systems SA
+
+ GNU Taler is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: LGPL3.0-or-later
+
+ Note: the LGPL does not apply to all components of GNU Taler,
+ but it does apply to this file.
+ */
+
+package tech.libeufin.util
+
+enum class LibeufinErrorCode(val code: Int) {
+
+ /**
+ * The error case didn't have a dedicate code.
+ */
+ LIBEUFIN_EC_NONE(0),
+
+ /**
+ * A payment being processed is neither CRDT not DBIT. This
+ * type of error should be detected _before_ storing the data
+ * into the database.
+ */
+ LIBEUFIN_EC_INVALID_PAYMENT_DIRECTION(1),
+
+ /**
+ * A bad piece of information made it to the database. For
+ * example, a transaction whose direction is neither CRDT nor DBIT
+ * was found in the database.
+ */
+ LIBEUFIN_EC_INVALID_STATE(2),
+
+ /**
+ * A bank's invariant is not holding anymore. For example, a customer's
+ * balance doesn't match the history of their bank account.
+ */
+ LIBEUFIN_EC_INCONSISTENT_STATE(3)
+}
+\ No newline at end of file