From 8d4a6f08c6af344fdf48d8d71e75d73e91d77301 Mon Sep 17 00:00:00 2001 From: Marko Milic Date: Tue, 2 Aug 2016 13:27:04 +0200 Subject: [PATCH] Closes #116 - Kafka connector : If non existing transaction_id is requested we should through 404 instead of 500 --- src/main/scala/code/api/util/APIUtil.scala | 2 ++ .../code/bankconnectors/KafkaMappedConnector.scala | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/scala/code/api/util/APIUtil.scala b/src/main/scala/code/api/util/APIUtil.scala index 808774c4c..585f508d6 100644 --- a/src/main/scala/code/api/util/APIUtil.scala +++ b/src/main/scala/code/api/util/APIUtil.scala @@ -106,6 +106,8 @@ object ErrorMessages { val InvalidAccountType = "OBP-30108: Invalid Account Type." val InitialBalanceMustBeZero = "OBP-30109: Initial Balance of Account must be Zero (0)." + + val ConnectorEmptyResponse = "OBP-30200: Connector cannot return the data we requested." val InvalidGetBankAccountsConnectorResponse = "OBP-30201: Connector did not return the set of accounts we requested." val InvalidGetBankAccountConnectorResponse = "OBP-30202: Connector did not return the account we requested." val InvalidGetTransactionConnectorResponse = "OBP-30203: Connector did not return the transaction we requested." diff --git a/src/main/scala/code/bankconnectors/KafkaMappedConnector.scala b/src/main/scala/code/bankconnectors/KafkaMappedConnector.scala index 3e6431132..8c6131148 100644 --- a/src/main/scala/code/bankconnectors/KafkaMappedConnector.scala +++ b/src/main/scala/code/bankconnectors/KafkaMappedConnector.scala @@ -223,10 +223,14 @@ object KafkaMappedConnector extends Connector with CreateViewImpls with Loggable "transactionId" -> transactionId.toString ) // Since result is single account, we need only first list entry implicit val formats = net.liftweb.json.DefaultFormats - val r = process(reqId, "getTransaction", argList).extract[KafkaInboundTransaction] - // Check does the response data match the requested data - if (transactionId.value != r.id) throw new Exception(ErrorMessages.InvalidGetTransactionConnectorResponse) - createNewTransaction(r) + val r = process(reqId, "getTransaction", argList).extractOpt[KafkaInboundTransaction] + r match { + // Check does the response data match the requested data + case Some(x) if transactionId.value != x.id => Failure(ErrorMessages.InvalidGetTransactionConnectorResponse, Empty, Empty) + case Some(x) if transactionId.value == x.id => createNewTransaction(x) + case _ => Failure(ErrorMessages.ConnectorEmptyResponse, Empty, Empty) + } + } override def getTransactions(bankId: BankId, accountID: AccountId, queryParams: OBPQueryParam*): Box[List[Transaction]] = {