Skip to content

Commit facb701

Browse files
authored
Merge pull request #2610 from constantine2nd/develop
Error handling
2 parents 8173d68 + 3b40372 commit facb701

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

‎obp-api/src/main/scala/code/bankaccountbalance/BankAccountBalance.scala‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
package code.bankaccountbalance
22

33
import code.model.dataAccess.MappedBankAccount
4+
import code.util.Helper.MdcLoggable
45
import code.util.{Helper, MappedUUID}
56
import com.openbankproject.commons.model.{AccountId, BalanceId, BankAccountBalanceTrait, BankId}
7+
import net.liftweb.common.{Empty, Failure, Full}
68
import net.liftweb.mapper._
79
import net.liftweb.util.Helpers.tryo
810

911
import java.util.Date
1012

11-
class BankAccountBalance extends BankAccountBalanceTrait with KeyedMapper[String, BankAccountBalance] with CreatedUpdated {
13+
class BankAccountBalance extends BankAccountBalanceTrait
14+
with KeyedMapper[String, BankAccountBalance]
15+
with CreatedUpdated
16+
with MdcLoggable {
1217

1318
override def getSingleton = BankAccountBalance
1419

@@ -36,8 +41,29 @@ class BankAccountBalance extends BankAccountBalanceTrait with KeyedMapper[String
3641
override def balanceType: String = BalanceType.get
3742
override def balanceAmount: BigDecimal = Helper.smallestCurrencyUnitToBigDecimal(BalanceAmount.get, foreignMappedBankAccountCurrency)
3843
override def lastChangeDateTime: Option[Date] = Some(this.updatedAt.get)
39-
override def referenceDate: Option[String] = Option(ReferenceDate.get).map(_.toString)
40-
44+
override def referenceDate: Option[String] = {
45+
net.liftweb.util.Helpers.tryo {
46+
Option(ReferenceDate.get) match {
47+
case Some(d) => Some(d.toString)
48+
case None =>
49+
logger.warn(s"ReferenceDate is missing for BalanceId=${BalanceId_.get}, AccountId=${AccountId_.get}, BankId=${BankId_.get}")
50+
None
51+
}
52+
} match {
53+
case Full(v) => v
54+
case f: Failure =>
55+
// extract throwable if present; otherwise create one from the message
56+
val t = f.exception.openOr(new RuntimeException(f.msg))
57+
logger.error(s"Error while retrieving referenceDate for BalanceId=${BalanceId_.get}, AccountId=${AccountId_.get}, BankId=${BankId_.get}: ${f.msg}", t)
58+
None
59+
case Empty =>
60+
// Defensive: treat as missing
61+
None
62+
}
63+
}
4164
}
4265

43-
object BankAccountBalance extends BankAccountBalance with KeyedMetaMapper[String, BankAccountBalance] with CreatedUpdated {}
66+
object BankAccountBalance
67+
extends BankAccountBalance
68+
with KeyedMetaMapper[String, BankAccountBalance]
69+
with CreatedUpdated {}

0 commit comments

Comments
 (0)