commit 554a31357786dc80cd5db5310b184ca532747566
parent 0dbf446b4f07778ac8556b483dcda65b66402b78
Author: MS <ms@taler.net>
Date: Fri, 10 Nov 2023 13:08:04 +0100
nexus
- handling write errors to log directories
- defining EBICS 'reachability' error code
Diffstat:
4 files changed, 23 insertions(+), 31 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/DbInit.kt
@@ -8,21 +8,6 @@ import tech.libeufin.util.resetDatabaseTables
import kotlin.system.exitProcess
/**
- * Runs the argument and fails the process, if that throws
- * an exception.
- *
- * @param getLambda function that might return a value.
- * @return the value from getLambda.
- */
-fun <T>doOrFail(getLambda: () -> T): T =
- try {
- getLambda()
- } catch (e: Exception) {
- logger.error(e.message)
- exitProcess(1)
- }
-
-/**
* This subcommand tries to load the SQL files that define
* the Nexus DB schema. Admits the --reset option to delete
* the data first.
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsFetch.kt
@@ -272,11 +272,7 @@ fun maybeLogFile(cfg: EbicsSetupConfig, content: ByteArray) {
val subDir = "${asUtcDate.year}-${asUtcDate.monthValue}-${asUtcDate.dayOfMonth}"
// Creating the combined dir.
val dirs = Path.of(maybeLogDir, subDir)
- try { dirs.createDirectories() }
- catch (e: Exception) {
- logger.error("Could not create log directory of path: $dirs") // check how dirs stringifies.
- exitProcess(1)
- }
+ doOrFail { dirs.createDirectories() }
// Write each ZIP entry in the combined dir.
content.unzipForEach { fileName, xmlContent ->
val f = File(dirs.toString(), "${now.toDbMicros()}_$fileName")
@@ -285,7 +281,7 @@ fun maybeLogFile(cfg: EbicsSetupConfig, content: ByteArray) {
logger.error("Log file exists already at: ${f.path}")
exitProcess(1)
}
- f.writeText(xmlContent)
+ doOrFail { f.writeText(xmlContent) }
}
}
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/EbicsSubmit.kt
@@ -52,7 +52,7 @@ enum class NexusSubmissionStage {
* They are both considered transient (non-200 responses
* can be fixed by changing and reloading the configuration).
*/
- http
+ reachability
}
/**
@@ -111,7 +111,7 @@ private suspend fun submitInitiatedPayment(
} catch (early: EbicsSideException) {
val errorStage = when (early.sideEc) {
EbicsSideError.HTTP_POST_FAILED ->
- NexusSubmissionStage.http // transient error
+ NexusSubmissionStage.reachability // transient error
/**
* Any other [EbicsSideError] should be treated as permanent,
* as they involve invalid signatures or an unexpected response
@@ -142,11 +142,7 @@ private suspend fun submitInitiatedPayment(
val asUtcDate = LocalDate.ofInstant(now, ZoneId.of("UTC"))
val subDir = "${asUtcDate.year}-${asUtcDate.monthValue}-${asUtcDate.dayOfMonth}"
val dirs = Path.of(logDir, subDir)
- try { dirs.createDirectories() }
- catch (e: Exception) {
- logger.error("Could not create log directory of path: $dirs")
- exitProcess(1)
- }
+ doOrFail { dirs.createDirectories() }
val f = File(
dirs.toString(),
"${now.toDbMicros()}_requestUid_${initiatedPayment.requestUid}_pain.001.xml"
@@ -156,7 +152,7 @@ private suspend fun submitInitiatedPayment(
logger.error("pain.001 log file exists already at: $f")
exitProcess(1)
}
- f.writeText(xml)
+ doOrFail { f.writeText(xml) }
}
}
@@ -254,7 +250,7 @@ private fun submitBatch(
* cases, the initiated payment stored in the database may still be correct,
* therefore we set this error as transient, and it'll be retried.
*/
- NexusSubmissionStage.http -> DatabaseSubmissionState.transient_failure
+ NexusSubmissionStage.reachability -> DatabaseSubmissionState.transient_failure
/**
* As in the pain.001 case, there is a fundamental problem in the document
* being submitted, so it should not be retried.
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt
@@ -51,7 +51,7 @@ import java.security.interfaces.RSAPrivateCrtKey
import java.security.interfaces.RSAPublicKey
val NEXUS_CONFIG_SOURCE = ConfigSource("libeufin-nexus", "libeufin-nexus")
-val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus.Main")
+val logger: Logger = LoggerFactory.getLogger("tech.libeufin.nexus")
val myJson = Json {
this.serializersModule = SerializersModule {
contextual(RSAPrivateCrtKey::class) { RSAPrivateCrtKeySerializer }
@@ -209,6 +209,21 @@ data class BankPublicKeysFile(
)
/**
+ * Runs the argument and fails the process, if that throws
+ * an exception.
+ *
+ * @param getLambda function that might return a value.
+ * @return the value from getLambda.
+ */
+fun <T>doOrFail(getLambda: () -> T): T =
+ try {
+ getLambda()
+ } catch (e: Exception) {
+ logger.error(e.message)
+ exitProcess(1)
+ }
+
+/**
* Load the bank keys file from disk.
*
* @param location the keys file location.