Prevent exception causes showing up as null in logs (#1018)

* Passing exception messages via constructor instead of overriding toString
This commit is contained in:
Andrius Dagys
2017-07-14 20:40:21 +01:00
committed by GitHub
parent a56540a3d6
commit 7aafcf8c57
6 changed files with 39 additions and 43 deletions

View File

@ -34,8 +34,8 @@ class ValidatingNotaryFlow(otherSide: Party, service: TrustedAuthorityNotaryServ
private fun checkSignatures(stx: SignedTransaction) {
try {
stx.verifySignatures(serviceHub.myInfo.notaryIdentity.owningKey)
} catch(e: SignedTransaction.SignaturesMissingException) {
throw NotaryException(NotaryError.SignaturesMissing(e))
} catch(e: SignatureException) {
throw NotaryException(NotaryError.TransactionInvalid(e))
}
}
@ -46,8 +46,8 @@ class ValidatingNotaryFlow(otherSide: Party, service: TrustedAuthorityNotaryServ
wtx.toLedgerTransaction(serviceHub).verify()
} catch (e: Exception) {
throw when (e) {
is TransactionVerificationException -> NotaryException(NotaryError.TransactionInvalid(e.toString()))
is SignatureException -> NotaryException(NotaryError.SignaturesInvalid(e.toString()))
is TransactionVerificationException,
is SignatureException -> NotaryException(NotaryError.TransactionInvalid(e))
else -> e
}
}

View File

@ -59,7 +59,8 @@ class ValidatingNotaryServiceTests {
val future = runClient(stx)
val ex = assertFailsWith(NotaryException::class) { future.getOrThrow() }
assertThat(ex.error).isInstanceOf(NotaryError.SignaturesInvalid::class.java)
val notaryError = ex.error as NotaryError.TransactionInvalid
assertThat(notaryError.cause).isInstanceOf(SignedTransaction.SignaturesMissingException::class.java)
}
@Test
@ -77,10 +78,10 @@ class ValidatingNotaryServiceTests {
val future = runClient(stx)
future.getOrThrow()
}
val notaryError = ex.error
assertThat(notaryError).isInstanceOf(NotaryError.SignaturesMissing::class.java)
val notaryError = ex.error as NotaryError.TransactionInvalid
assertThat(notaryError.cause).isInstanceOf(SignedTransaction.SignaturesMissingException::class.java)
val missingKeys = (notaryError as NotaryError.SignaturesMissing).cause.missing
val missingKeys = (notaryError.cause as SignedTransaction.SignaturesMissingException).missing
assertEquals(setOf(expectedMissingKey), missingKeys)
}