gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: Define LibEuFin error codes.


From: gnunet
Subject: [libeufin] branch master updated: Define LibEuFin error codes.
Date: Mon, 06 Sep 2021 12:17:23 +0200

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new baf3f56  Define LibEuFin error codes.
baf3f56 is described below

commit baf3f567a3cd5551669ff29d28ef72520cea5966
Author: MS <ms@taler.net>
AuthorDate: Mon Sep 6 10:16:55 2021 +0000

    Define LibEuFin error codes.
---
 .../tech/libeufin/sandbox/EbicsProtocolBackend.kt  |  2 +
 .../src/main/kotlin/tech/libeufin/sandbox/Main.kt  |  6 ++-
 .../kotlin/tech/libeufin/sandbox/bankAccount.kt    |  8 ++--
 util/src/main/kotlin/LibeufinErrorCodes.kt         | 52 ++++++++++++++++++++++
 4 files changed, 62 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
index e0d26d9..6dccba3 100644
--- 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
index 243cb60..2db5ad7 100644
--- 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
index 6dd0c01..70c86df 100644
--- 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
new file mode 100644
index 0000000..f1c1828
--- /dev/null
+++ 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

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]