Skip to content

The application crashes when it is unable to connect to its authentication server (Keycloak) #3821

@allan-on

Description

@allan-on

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:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. 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:

  1. More robust - Currently, other potential exceptions (like SocketTimeoutException, IOException, etc.) aren't caught and would crash
  2. More concise - Less code duplication
  3. 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

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions