Skip to content

Commit 371b258

Browse files
waltkbJakeFernandes98
authored andcommitted
Policy exceptions
1 parent ee47a56 commit 371b258

3 files changed

Lines changed: 206 additions & 150 deletions

File tree

waltid-libraries/credentials/waltid-verification-policies2/src/commonMain/kotlin/id/walt/policies2/vc/policies/status/StatusPolicyImplementation.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ object StatusPolicyImplementation {
108108
private suspend fun processW3C(
109109
data: JsonElement,
110110
attribute: W3CStatusPolicyAttribute
111-
): Result<Unit> {
111+
): Result<Unit> = runCatching {
112112
val statusEntry = w3cEntryContentParser.parse(data)
113-
return w3cStatusValidator.validate(statusEntry, attribute)
113+
w3cStatusValidator.validate(statusEntry, attribute).getOrThrow()
114114
}
115115

116116
private suspend fun processListW3C(
@@ -147,9 +147,9 @@ object StatusPolicyImplementation {
147147
private suspend fun processIETF(
148148
data: JsonElement,
149149
attribute: IETFStatusPolicyAttribute
150-
): Result<Unit> {
150+
): Result<Unit> = runCatching {
151151
val statusEntry = ietfEntryContentParser.parse(data)
152-
return ietfStatusValidator.validate(statusEntry, attribute)
152+
ietfStatusValidator.validate(statusEntry, attribute).getOrThrow()
153153
}
154154

155155
private fun getStatusEntryElementExtractor(args: StatusPolicyArgument) = when (args) {

waltid-libraries/protocols/waltid-openid4vp-verifier/src/commonMain/kotlin/id/walt/verifier2/handlers/vpresponse/Verifier2SessionCredentialPolicyValidation.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ object Verifier2SessionCredentialPolicyValidation {
3737
policies.vc_policies?.policies.orEmpty().map { policy ->
3838
async(Dispatchers.Default) {
3939
log.trace { "Validating '$queryId' credential#$credentialIndex with policy '${policy.id}': $credential" }
40-
val result = policy.verify(credential, context)
40+
val result = runCatching { policy.verify(credential, context) }
41+
.getOrElse { ex ->
42+
log.warn { "Policy '${policy.id}' threw an unexpected exception for '$queryId' credential#$credentialIndex: ${ex.message}" }
43+
Result.failure(ex)
44+
}
4145
log.trace { "'$queryId' credential#$credentialIndex '${policy.id}' result: $result" }
4246

4347
CredentialPolicyResult(
@@ -60,7 +64,11 @@ object Verifier2SessionCredentialPolicyValidation {
6064
credentials.flatMapIndexed { credentialIndex, specificCredential ->
6165
queryPolicies.policies.map { policy ->
6266
async(Dispatchers.Default) {
63-
val result = policy.verify(specificCredential, context)
67+
val result = runCatching { policy.verify(specificCredential, context) }
68+
.getOrElse { ex ->
69+
log.warn { "Specific policy '${policy.id}' threw an unexpected exception for '$queryId' credential#$credentialIndex: ${ex.message}" }
70+
Result.failure(ex)
71+
}
6472

6573
queryId to CredentialPolicyResult(
6674
policy = policy,

0 commit comments

Comments
 (0)