-
Notifications
You must be signed in to change notification settings - Fork 74
Description
Describe the bug
The app crashes when it can't connect to Keycloak when Keycloak is offline (e.g. when the Keycloak server is undergoing maintenance or is temporarily offline).
The failure happens when attempting oAuthService.fetchToken(body) in TokenAuthenticator.kt, and the fatal exception java.net.ConnectException: failed to connect to keycloak.. is thrown.
To Reproduce
Steps to reproduce the behaviour:
- Go to '...'
- Click on '....'
- Scroll down to '....'
- See error
Expected behaviour
The application should handle the connection failure gracefully.
Currently, four exception types are handled identically - they all just wrap the exception in Result.failure():
catch (httpException: HttpException) {
Result.failure(httpException)
} catch (unknownHostException: UnknownHostException) {
Result.failure(unknownHostException)
} catch (sslHandShakeException: SSLHandshakeException) {
Result.failure(sslHandShakeException)
} catch (connectException: ConnectException) {
Result.failure(connectException)
}Since all exceptions are handled the same way, generic exception handling would be better because:
- More robust - Currently, other potential exceptions (like
SocketTimeoutException,IOException, etc.) aren't caught and would crash - More concise - Less code duplication
- Same behaviour - No specific handling logic differs between exception types
Screenshots
If applicable, add screenshots to help explain your problem.
Smartphone (please complete the following information):
- Device: [e.g. Samsung Galaxy A2 emulator]
- Android version: [e.g. Settings -> About phone -> Android version]
- Build number: [e.g. Settings -> About phone -> Build number]
- Version [e.g. 24]
Additional context