feature/POC - Translate the error message using i18n props -step7

This commit is contained in:
hongwei 2022-07-07 14:30:47 +02:00
parent 0b07518737
commit b928b75486
4 changed files with 19 additions and 6 deletions

View File

@ -79,7 +79,7 @@ case class APIFailureNewStyle(failMsg: String,
def translatedErrorMessage = {
val errorCode = extractErrorMessageCode(failMsg)
val errorBody = failMsg.split(": ").drop(1).reduceLeft(_ + _)
val errorBody = extractErrorMessageBody(failMsg)
val localeUrlParameter = getHttpRequestUrlParam(ccl.map(_.url).getOrElse(""),"Locale")
val locale = I18NUtil.computeLocale(localeUrlParameter)
@ -142,7 +142,7 @@ case class APIFailureNewStyle(failMsg: String,
)
val translatedErrorBody = ?(errorCode, locale)
s"$errorCode: $translatedErrorBody"
s"$errorCode$translatedErrorBody"
}
}

View File

@ -4206,7 +4206,18 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
//eg: UserHasMissingRoles = "OBP-20006: User is missing one or more roles:" -->
// errorCode = "OBP-20006"
// errorCode = "OBP-20006:"
// So far we support the i180n, we need to separate the errorCode and errorBody
def extractErrorMessageCode (errorMessage: String) = errorMessage.split(": ").head
def extractErrorMessageCode (errorMessage: String) = {
val regex = "(OBP-\\d+):".r
regex.findFirstIn(errorMessage).mkString
}
//eg: UserHasMissingRoles = "OBP-20006: User is missing one or more roles:" -->
// errorBody = " User is missing one or more roles:"
// So far we support the i180n, we need to separate the errorCode and errorBody
def extractErrorMessageBody(errorMessage: String) = {
val regex = "(OBP-\\d+):"
errorMessage.replaceFirst(regex,"")
}
}

View File

@ -3,6 +3,7 @@ package code.api.v4_0_0
import com.openbankproject.commons.model.ErrorMessage
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON
import code.api.util.APIUtil.OAuth._
import code.api.util.APIUtil.extractErrorMessageCode
import code.api.util.ApiRole.CanCreateDirectDebitAtOneBank
import com.openbankproject.commons.util.ApiVersion
import code.api.util.ErrorMessages.{NoViewPermission, UserHasMissingRoles, UserNotLoggedIn}
@ -45,7 +46,7 @@ class DirectDebitTest extends V400ServerSetup {
val response400 = makePostRequest(request400, write(postDirectDebitJsonV400))
Then("We should get a 400")
response400.code should equal(400)
response400.body.extract[ErrorMessage].message should startWith(NoViewPermission)
response400.body.extract[ErrorMessage].message contains extractErrorMessageCode(NoViewPermission) should be (true)
}
}

View File

@ -3,6 +3,7 @@ package code.api.v4_0_0
import com.openbankproject.commons.model.ErrorMessage
import code.api.util.APIUtil.OAuth._
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON
import code.api.util.APIUtil.extractErrorMessageCode
import code.api.util.ApiRole.CanCreateStandingOrderAtOneBank
import com.openbankproject.commons.util.ApiVersion
import code.api.util.ErrorMessages.{NoViewPermission, UserHasMissingRoles, UserNotLoggedIn}
@ -45,7 +46,7 @@ class StandingOrderTest extends V400ServerSetup {
val response400 = makePostRequest(request400, write(postStandingOrderJsonV400))
Then("We should get a 400")
response400.code should equal(400)
response400.body.extract[ErrorMessage].message should startWith(NoViewPermission)
response400.body.extract[ErrorMessage].message contains extractErrorMessageCode(NoViewPermission) should be (true)
}
}