mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 17:56:46 +00:00
Refactor a call to Box.get to handle the error case
This commit is contained in:
parent
7003b1736f
commit
fb96e8f59f
@ -216,7 +216,7 @@ private object LocalConnector extends Connector with Loggable {
|
||||
|
||||
def saveAndUpdateAccountBalance(transactionJS : JValue, thisAccount : Account) : Box[OBPEnvelope] = {
|
||||
|
||||
val envelope: Box[OBPEnvelope] = OBPEnvelope.envlopesFromJvalue(transactionJS)
|
||||
val envelope: Box[OBPEnvelope] = OBPEnvelope.envelopesFromJValue(transactionJS)
|
||||
|
||||
if(envelope.isDefined) {
|
||||
val e : OBPEnvelope = envelope.get
|
||||
|
||||
@ -188,18 +188,23 @@ class OBPEnvelope private() extends MongoRecord[OBPEnvelope] with ObjectIdPk[OBP
|
||||
|
||||
object OBPEnvelope extends OBPEnvelope with MongoMetaRecord[OBPEnvelope] with Loggable {
|
||||
|
||||
def envlopesFromJvalue(jval: JValue) : Box[OBPEnvelope] = {
|
||||
val created = fromJValue(jval)
|
||||
val errors = created.get.validate
|
||||
if(errors.isEmpty)
|
||||
created match {
|
||||
case Full(e) => Full(e)
|
||||
case _ => Failure("could not create Envelope form JValue")
|
||||
}
|
||||
else{
|
||||
logger.warn("could not create a obp envelope.errors: ")
|
||||
logger.warn(errors)
|
||||
Empty
|
||||
def envelopesFromJValue(jval: JValue) : Box[OBPEnvelope] = {
|
||||
val createdBox = fromJValue(jval)
|
||||
|
||||
createdBox match {
|
||||
case Full(created) =>
|
||||
val errors = created.validate
|
||||
if(errors.isEmpty) {
|
||||
Full(created)
|
||||
} else {
|
||||
logger.warn("could not create a obp envelope.errors: ")
|
||||
logger.warn(errors)
|
||||
Empty
|
||||
}
|
||||
case Failure(msg, _, _) =>
|
||||
Failure(s"could not create Envelope from JValue: $msg")
|
||||
case _ =>
|
||||
Failure(s"could not create Envelope from JValue")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ object ImporterAPI extends RestHelper with Loggable {
|
||||
def savetransactions ={
|
||||
val rawEnvelopes = json._1.children
|
||||
val envelopes : List[OBPEnvelope]= rawEnvelopes.flatMap(e => {
|
||||
OBPEnvelope.envlopesFromJvalue(e)
|
||||
OBPEnvelope.envelopesFromJValue(e)
|
||||
})
|
||||
|
||||
def updateAccountBalance(accountNumber: String, bankId: String, account: Account) = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user