commit 7e326c6e14c9c130b072f04f9ba2693fc730c52e
parent 97ab4b906bcf280790527f3c101933592fc33a56
Author: MS <ms@taler.net>
Date: Wed, 15 Feb 2023 15:57:01 +0100
Error management.
Checking bank-technical error code even
along the upload helper.
Diffstat:
1 file changed, 28 insertions(+), 11 deletions(-)
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsClient.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/ebics/EbicsClient.kt
@@ -260,16 +260,25 @@ suspend fun doEbicsUploadTransaction(
if (initResponse.technicalReturnCode != EbicsReturnCode.EBICS_OK) {
throw NexusError(
HttpStatusCode.InternalServerError,
- reason = "unexpected return code"
+ reason = "EBICS-technical error at init phase:" +
+ " ${initResponse.technicalReturnCode} ${initResponse.reportText}"
)
}
// The bank did NOT indicate any error, but the response
// lacks required information, blame the bank.
val transactionID = initResponse.transactionID ?: throw NexusError(
HttpStatusCode.BadGateway,
- "init response must have transaction ID"
+ "Init response must have transaction ID"
)
- logger.debug("Bank acknowledges EBICS upload initialization. Transaction ID: $transactionID.")
+ if (initResponse.bankReturnCode != EbicsReturnCode.EBICS_OK) {
+ throw NexusError(
+ HttpStatusCode.InternalServerError,
+ reason = "Bank-technical error at init phase:" +
+ " ${initResponse.technicalReturnCode}"
+ )
+ }
+ logger.debug("Bank acknowledges EBICS upload initialization. " +
+ " Transaction ID: $transactionID.")
/* now send actual payload */
val ebicsPayload = createEbicsRequestForUploadTransferPhase(
@@ -284,21 +293,29 @@ suspend fun doEbicsUploadTransaction(
)
val txResp = parseAndValidateEbicsResponse(subscriberDetails, txRespStr)
when (txResp.technicalReturnCode) {
- EbicsReturnCode.EBICS_OK -> {
- }
+ EbicsReturnCode.EBICS_OK -> {/* do nothing */}
else -> {
+ // EBICS failed, blame Nexus.
throw EbicsProtocolError(
- /**
- * The communication was valid, but the content may have
- * caused a problem in the bank. Nexus MAY but it's not required
- * to check all possible business conditions before requesting
- * to the bank. */
- httpStatusCode = HttpStatusCode.UnprocessableEntity,
+ httpStatusCode = HttpStatusCode.InternalServerError,
reason = txResp.reportText,
ebicsTechnicalCode = txResp.technicalReturnCode
)
}
}
+ when (txResp.bankReturnCode) {
+ EbicsReturnCode.EBICS_OK -> {/* do nothing */}
+ else -> {
+ /**
+ * Although EBICS went fine, the bank complained about
+ * the communication content.
+ */
+ throw EbicsProtocolError(
+ httpStatusCode = HttpStatusCode.UnprocessableEntity,
+ reason = "bank-technical error: ${txResp.reportText}"
+ )
+ }
+ }
logger.debug("Bank acknowledges EBICS upload transfer. Transaction ID: $transactionID")
}