auth0 / jwks-rsa-java

MIT License
195 stars 73 forks source link

Throw proper exception from cached provider #169

Closed jimmyjames closed 1 year ago

jimmyjames commented 1 year ago

Prior to this change, if using a cached JWK provider (the default), any exception caught when accessing the JWK would be a SigningKeyNotFoundException, with a cause of ExecutionException (thrown by the cache provider).

Since the cause of an exception may be for different reasons (e.g., network exception, KID not found), developers would need to unwrap the SigningKeyNotFoundException to get the ExecutionException, which itself would contain the specific reason for failure (some JwkException).

As raised in #165, this is cumbersome. Instead, this PR throws the causing exception directly, so that developers can more easily identify why the operation failed.

Fixes #165

jimmyjames commented 1 year ago

codecov failure due to fall-thru line not being covered. Since ExecutionException is only thrown for checked exceptions, and JwkProvider#get() only throws a JwkException, the instance checking and fallback are a bit overly careful. The effort to test such a case does not seem worthwhile since it's not a realistic scenario and simple mocking will not work as the provider cannot throw anything other than a JwkException.