Skip to content

Commit 39c44f6

Browse files
#22 - networking treatment using flow or Coroutines with Result
1 parent 7e006bb commit 39c44f6

File tree

2 files changed

+55
-29
lines changed
  • core-networking/src/main

2 files changed

+55
-29
lines changed
Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,55 @@
11
package com.codandotv.streamplayerapp.core_networking.handleError
22

3+
import com.codandotv.streamplayerapp.core_networking.R
4+
import org.koin.core.component.KoinComponent
5+
36
/**
47
* Base Class for handling errors/failures/exceptions.
58
*/
6-
sealed class Failure(val code: Int? = -1, val errorMessage: String) : java.lang.Exception() {
7-
data class NoDataContent(val codeStatus: Int? = null) : Failure(codeStatus, "No data content")
8-
data class ServerError(val codeStatus: Int? = null) : Failure(codeStatus, "Server error!")
9-
data class GenericError(val codeStatus: Int? = -12,
10-
private val msg: String? = null) : Failure(codeStatus, msg
11-
?: MSG_DEFAULT)
12-
13-
data class NetworkError(val codeStatus: Int? = -13,
14-
private val throwable: Throwable) : Failure(codeStatus, "Sem conexão. Verifique o wifi ou dados móveis e tente novamente em alguns instantes.")
15-
16-
data class UnknownError(val codeStatus: Int? = null,
17-
private val throwable: Throwable? = Exception()) : Failure(codeStatus, throwable?.message
18-
?: MSG_DEFAULT)
19-
20-
data class UnexpectedApiException(val codeStatus: Int? = -14,
21-
private val throwable: Throwable? = Exception()) : Failure(codeStatus, throwable?.message
22-
?: MSG_DEFAULT)
23-
24-
data class ClientException(val codeStatus: Int? = -15,
25-
private val throwable: Throwable? = Exception()) : Failure(codeStatus, throwable?.message
26-
?: MSG_DEFAULT)
27-
28-
data class UnparsableResponseException(val codeStatus: Int? = -16,
29-
private val throwable: Throwable? = Exception()) : Failure(codeStatus, throwable?.message
30-
?: MSG_DEFAULT)
31-
32-
companion object {
33-
private const val MSG_DEFAULT = "Não foi possível concluir. Estamos trabalhando para resolver. Tente novamente em alguns instantes."
34-
}
9+
sealed class Failure(
10+
val code: Int? = -1,
11+
val errorMessage: String? = null,
12+
val errorMessageRes: Int = R.string.core_networking_msg_default_error
13+
) : Exception(), KoinComponent {
14+
data class NoDataContent(val codeStatus: Int? = null) :
15+
Failure(codeStatus, errorMessageRes = R.string.core_networking_no_data_content)
16+
17+
data class ServerError(val codeStatus: Int? = null) :
18+
Failure(codeStatus, errorMessageRes = R.string.core_networking_no_server_error)
19+
20+
data class GenericError(
21+
val codeStatus: Int? = -12, private val msg: String? = null
22+
) : Failure(
23+
codeStatus
24+
)
25+
26+
data class NetworkError(
27+
val codeStatus: Int? = -13, private val throwable: Throwable
28+
) : Failure(
29+
codeStatus, errorMessageRes = R.string.core_networking_networking_error
30+
)
31+
32+
data class UnknownError(
33+
val codeStatus: Int? = null, private val throwable: Throwable? = Exception()
34+
) : Failure(
35+
codeStatus, throwable?.message
36+
)
37+
38+
data class UnexpectedApiException(
39+
val codeStatus: Int? = -14, private val throwable: Throwable? = Exception()
40+
) : Failure(
41+
codeStatus, throwable?.message
42+
)
43+
44+
data class ClientException(
45+
val codeStatus: Int? = -15, private val throwable: Throwable? = Exception()
46+
) : Failure(
47+
codeStatus, throwable?.message
48+
)
49+
50+
data class UnparsableResponseException(
51+
val codeStatus: Int? = -16, private val throwable: Throwable? = Exception()
52+
) : Failure(
53+
codeStatus, throwable?.message
54+
)
3555
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<resources>
2+
<string name="core_networking_msg_default_error">Não foi possível concluir. Estamos trabalhando para resolver. Tente novamente em alguns instantes.</string>
3+
<string name="core_networking_no_data_content">Sem conteúdo de dados</string>
4+
<string name="core_networking_no_server_error">Erro no servidor</string>
5+
<string name="core_networking_networking_error">Sem conexão. Verifique o wifi ou dados móveis e tente novamente em alguns instantes.</string>
6+
</resources>

0 commit comments

Comments
 (0)