From 83a197cdded36f71c884104587cd67d2f494ce92 Mon Sep 17 00:00:00 2001 From: vijayg10 <33152110+vijayg10@users.noreply.github.com> Date: Thu, 26 May 2022 23:52:29 +0530 Subject: [PATCH] fix: error codes for liquidity and ndc limit check (#901) fix: error codes for liquidity and ndc limit check (#901) --- src/handlers/positions/handler.js | 8 ++++---- src/models/position/facade.js | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/handlers/positions/handler.js b/src/handlers/positions/handler.js index 28ec75b35..19644dd51 100644 --- a/src/handlers/positions/handler.js +++ b/src/handlers/positions/handler.js @@ -155,7 +155,7 @@ const positions = async (error, messages) => { } if (Array.isArray(preparedMessagesList) && preparedMessagesList.length > 0) { const prepareMessage = preparedMessagesList[0] - const { transferState } = prepareMessage + const { transferState, fspiopError } = prepareMessage if (transferState.transferStateId === Enum.Transfers.TransferState.RESERVED) { Logger.isInfoEnabled && Logger.info(Utility.breadcrumb(location, `payer--${actionLetter}1`)) await Kafka.proceed(Config.KAFKA_CONFIG, params, { consumerCommit, eventDetail }) @@ -163,11 +163,11 @@ const positions = async (error, messages) => { return true } else { Logger.isInfoEnabled && Logger.info(Utility.breadcrumb(location, `payerNotifyInsufficientLiquidity--${actionLetter}2`)) - const fspiopError = ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.PAYER_FSP_INSUFFICIENT_LIQUIDITY) - const fspiopApiError = fspiopError.toApiErrorObject(Config.ERROR_HANDLING) + const responseFspiopError = fspiopError || ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.INTERNAL_SERVER_ERROR) + const fspiopApiError = responseFspiopError.toApiErrorObject(Config.ERROR_HANDLING) await TransferService.logTransferError(transferId, fspiopApiError.errorInformation.errorCode, fspiopApiError.errorInformation.errorDescription) await Kafka.proceed(Config.KAFKA_CONFIG, params, { consumerCommit, fspiopError: fspiopApiError, eventDetail, fromSwitch }) - throw fspiopError + throw responseFspiopError } } } else if (eventType === Enum.Events.Event.Type.POSITION && [Enum.Events.Event.Action.COMMIT, Enum.Events.Event.Action.RESERVE, Enum.Events.Event.Action.BULK_COMMIT].includes(action)) { diff --git a/src/models/position/facade.js b/src/models/position/facade.js index dcea431c7..94d395fb2 100644 --- a/src/models/position/facade.js +++ b/src/models/position/facade.js @@ -184,11 +184,13 @@ const prepareChangeParticipantPositionTransaction = async (transferList) => { if (new MLNumber(availablePositionBasedOnLiquidityCover).toNumber() < transferAmount.toNumber()) { transferState.transferStateId = Enum.Transfers.TransferInternalState.ABORTED_REJECTED transferState.reason = ErrorHandler.Enums.FSPIOPErrorCodes.PAYER_FSP_INSUFFICIENT_LIQUIDITY.message - rawMessage.value.content.payload = ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.PAYER_FSP_INSUFFICIENT_LIQUIDITY, null, null, null, rawMessage.value.content.payload.extensionList).toApiErrorObject(Config.ERROR_HANDLING) + reservedTransfers[transferId].fspiopError = ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.PAYER_FSP_INSUFFICIENT_LIQUIDITY, null, null, null, rawMessage.value.content.payload.extensionList) + rawMessage.value.content.payload = reservedTransfers[transferId].fspiopError.toApiErrorObject(Config.ERROR_HANDLING) } else if (new MLNumber(availablePositionBasedOnPayerLimit).toNumber() < transferAmount.toNumber()) { transferState.transferStateId = Enum.Transfers.TransferInternalState.ABORTED_REJECTED transferState.reason = ErrorHandler.Enums.FSPIOPErrorCodes.PAYER_LIMIT_ERROR.message - rawMessage.value.content.payload = ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.PAYER_LIMIT_ERROR, null, null, null, rawMessage.value.content.payload.extensionList).toApiErrorObject(Config.ERROR_HANDLING) + reservedTransfers[transferId].fspiopError = ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.PAYER_LIMIT_ERROR, null, null, null, rawMessage.value.content.payload.extensionList) + rawMessage.value.content.payload = reservedTransfers[transferId].fspiopError.toApiErrorObject(Config.ERROR_HANDLING) } else { availablePositionBasedOnLiquidityCover = new MLNumber(availablePositionBasedOnLiquidityCover).subtract(transferAmount).toFixed(Config.AMOUNT.SCALE) availablePositionBasedOnPayerLimit = new MLNumber(availablePositionBasedOnPayerLimit).subtract(transferAmount).toFixed(Config.AMOUNT.SCALE)