mirror of
https://github.com/Matte23/circolapp.git
synced 2025-12-05 23:19:10 +00:00
Handle generic errors
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user