docfix/Enhance error handling of Consent Flow

This commit is contained in:
Marko Milić 2023-02-08 12:32:00 +01:00
parent 1e27416867
commit 80aa925b68
2 changed files with 12 additions and 5 deletions

View File

@ -215,7 +215,8 @@ object Consent {
val bankId = if (role.requiresBankId) entitlement.bank_id else ""
Entitlement.entitlement.vend.addEntitlement(bankId, user.userId, entitlement.role_name) match {
case Full(_) => (entitlement, "AddedOrExisted")
case _ => (entitlement, "Cannot add the entitlement: " + entitlement)
case _ =>
(entitlement, "Cannot add the entitlement: " + entitlement)
}
case true =>
(entitlement, "AddedOrExisted")
@ -237,7 +238,8 @@ object Consent {
val failedToAdd: List[(Role, String)] = triedToAdd.filter(_._2 != "AddedOrExisted")
failedToAdd match {
case Nil => Full(user)
case _ => Failure("The entitlements cannot be added. " + failedToAdd.map(_._1).mkString(", "))
case _ =>
Failure("The entitlements cannot be added. " + failedToAdd.map(i => (i._1, i._2)).mkString(", "))
}
case _ =>
Failure("Cannot get entitlements for user id: " + user.userId)
@ -334,6 +336,8 @@ object Consent {
case _ =>
(Failure(ErrorMessages.UnknownError), Some(cc))
}
case failure@Failure(msg, exp, chain) => // Handled errors
(Failure(msg), Some(cc))
case _ =>
(Failure("Cannot add entitlements based on: " + consentAsJwt), Some(cc))
}
@ -423,6 +427,8 @@ object Consent {
case _ =>
(Failure(ErrorMessages.UnknownError), Some(cc))
}
case failure@Failure(msg, exp, chain) => // Handled errors
(Failure(msg), Some(cc))
case _ =>
(Failure("Cannot add entitlements based on: " + consentId), Some(cc))
}

View File

@ -17,7 +17,7 @@ import code.api.v3_0_0.JSONFactory300
import code.api.v3_1_0._
import code.api.v4_0_0.JSONFactory400.createCustomersMinimalJson
import code.api.v4_0_0.{JSONFactory400, PutProductJsonV400}
import code.api.v5_0_0.JSONFactory500.{createPhysicalCardJson, createViewJsonV500, createViewsJsonV500, createViewsIdsJsonV500}
import code.api.v5_0_0.JSONFactory500.{createPhysicalCardJson, createViewJsonV500, createViewsIdsJsonV500, createViewsJsonV500}
import code.bankconnectors.Connector
import code.consent.{ConsentRequests, Consents}
import code.entitlement.Entitlement
@ -44,6 +44,7 @@ import java.util.concurrent.ThreadLocalRandom
import code.accountattribute.AccountAttributeX
import code.util.Helper.booleanToFuture
import code.views.system.AccountAccess
import scala.collection.immutable.{List, Nil}
import scala.collection.mutable.ArrayBuffer
@ -905,7 +906,7 @@ trait APIMethods500 {
_ <- scaMethod match {
case v if v == StrongCustomerAuthentication.EMAIL.toString => // Send the email
for{
failMsg <- Future {s"$InvalidJsonFormat The Json body should be the $PostConsentEmailJsonV310"}
failMsg <- Future {s"$InvalidJsonFormat The Json body must contain the field email"}
consentScaEmail <- NewStyle.function.tryons(failMsg, 400, callContext) {
consentRequestJson.email.head
}
@ -920,7 +921,7 @@ trait APIMethods500 {
case v if v == StrongCustomerAuthentication.SMS.toString => // Not implemented
for {
failMsg <- Future {
s"$InvalidJsonFormat The Json body should be the $PostConsentPhoneJsonV310"
s"$InvalidJsonFormat The Json body must contain the field phone_number"
}
consentScaPhoneNumber <- NewStyle.function.tryons(failMsg, 400, callContext) {
consentRequestJson.phone_number.head