Error handling

Silhouette throws a huge range of exceptions from its core. But it's easy to handle these in your application, because they are grouped and therefore you can either react to single errors or to a group of errors to provide your users an appropriated result.

Exception types

Below you can find the exception hierarchy provided by Silhouette.

SilhouetteException

This is the base exception. All other exceptions are derived from this exception. So to react to all Silhouette related errors you must only catch this exception.

NotAuthenticatedException

This exception type indicates that a user is not authenticated to access a secured endpoint. This exception type will be handled by the endpoint error handlers.

NotAuthorizedException

This exception type indicates that the authenticated user is not authorized to access a secured endpoint. This exception type will be handled by the endpoint error handlers.

CryptoException

This exception type indicates that an error occurred in a cryptography related functionality.

AuthenticatorException

This is the base exception for all authenticator related errors. Silhouette provides also some derived exceptions types which allow you to react of single authenticator related errors. Below you can see the list of them:

TypeDescription
AuthenticatorCreationExceptionAn exception thrown when there is an error during authenticator creation
AuthenticatorRetrievalExceptionAn exception thrown when there is an error during authenticator retrieval
AuthenticatorInitializationExceptionAn exception thrown when there is an error during authenticator initialization
AuthenticatorUpdateExceptionAn exception thrown when there is an error during authenticator update
AuthenticatorRenewalExceptionAn exception thrown when there is an error during authenticator renewal
AuthenticatorDiscardingExceptionAn exception thrown when there is an error during authenticator discarding

ProviderException

This is the base exception for all provider related errors. Silhouette provides also some derived exceptions types which allow you to react of single provider related errors. Below you can see the list of them:

TypeDescription
AccessDeniedExceptionSignals that a social provider denies access during authentication process
IdentityNotFoundExceptionSignals that an identity could not found in a credential based provider
InvalidPasswordExceptionIndicates that an invalid password was entered in a credential based provider
OAuth1TokenSecretExceptionIndicates that an error occurred during OAuth1 token secret retrieval
OAuth2StateExceptionIndicates that an error occurred during OAuth2 state retrieval
ProfileRetrievalExceptionIndicates that an error occurred during profile retrieval in a social provider
UnexpectedResponseExceptionSignals that an unexpected response was received from a social provider

ConfigurationException

This exception type indicates a misconfiguration of a Silhouette component.

πŸ“˜

Note

Due to the asynchronous nature of Silhouette, all exceptions will be thrown in Futures. This means that exceptions may not be caught in a try catch block because Futures may be executed in separate Threads. To solve this problem, Futures have their own error handling mechanism. They can be recovered from an error state into desirable state with the help of the recover and recoverWith methods. Both methods accept a partial function which transforms the Exception into any other type. For more information please visit the Future trait's documentation.


What’s Next