Handle generic errors

This commit is contained in:
2021-01-15 11:00:52 +01:00
parent 45034b294c
commit 5550de5836
10 changed files with 34 additions and 18 deletions

View File

@@ -11,9 +11,13 @@ class CircularRepository(
var errorCode = 0
val result = serverAPI.getCircularsFromServer()
if (result.second == ServerAPI.Companion.Result.ERROR)
if (result.second == ServerAPI.Companion.Result.GENERIC_ERROR)
return Pair(emptyList(), -1)
if (result.second == ServerAPI.Companion.Result.NETWORK_ERROR)
return Pair(emptyList(), -2)
val oldCirculars = circularDao.getCirculars(serverAPI.serverID())
val newCirculars = result.first

View File

@@ -38,8 +38,11 @@ class ServerAPI(serverName: Servers) {
suspend fun getCircularsFromServer(): Pair<List<Circular>, Result> = withContext(PlatformDispatcher.IO) {
val newCircularsAvailable = server.newCircularsAvailable()
if (newCircularsAvailable.second == Result.ERROR)
return@withContext Pair(emptyList(), Result.ERROR)
if (newCircularsAvailable.second == Result.GENERIC_ERROR)
return@withContext Pair(emptyList(), Result.GENERIC_ERROR)
if (newCircularsAvailable.second == Result.NETWORK_ERROR)
return@withContext Pair(emptyList(), Result.NETWORK_ERROR)
if (!newCircularsAvailable.first)
return@withContext Pair(emptyList(), Result.SUCCESS)
@@ -57,7 +60,7 @@ class ServerAPI(serverName: Servers) {
}
enum class Result {
SUCCESS, ERROR
SUCCESS, NETWORK_ERROR, GENERIC_ERROR
}
val numberOfServers = Servers.values().size

View File

@@ -22,7 +22,9 @@ class CurieServer(ktorClient: HttpClient) : Server(ktorClient) {
Pair(list, ServerAPI.Companion.Result.SUCCESS)
}
} catch (exception: IOException) {
Pair(emptyList(), ServerAPI.Companion.Result.ERROR)
Pair(emptyList(), ServerAPI.Companion.Result.NETWORK_ERROR)
} catch (exception: Exception) {
Pair(emptyList(), ServerAPI.Companion.Result.GENERIC_ERROR)
}
}

View File

@@ -43,7 +43,9 @@ class PorporatoServer(ktorClient: HttpClient) : Server(ktorClient) {
Pair(list, ServerAPI.Companion.Result.SUCCESS)
} catch (exception: IOException) {
Pair(emptyList(), ServerAPI.Companion.Result.ERROR)
Pair(emptyList(), ServerAPI.Companion.Result.NETWORK_ERROR)
} catch (exception: Exception) {
Pair(emptyList(), ServerAPI.Companion.Result.GENERIC_ERROR)
}
}