@@ -17,8 +17,13 @@ internal data class Success(val response: String) : EventUploadResult
17
17
/* *
18
18
* `EventUploadError` is a sealed interface representing an error that occurred during event upload.
19
19
* It can be either a retry able error or a non-retry able error.
20
+ *
21
+ * @property responseCode The HTTP response code associated with the error, if available.
20
22
*/
21
- internal sealed interface EventUploadError : EventUploadResult
23
+ internal sealed interface EventUploadError : EventUploadResult {
24
+
25
+ val responseCode: Int?
26
+ }
22
27
23
28
/* *
24
29
* `RetryAbleError` is a sealed interface representing an event upload error that can be retried.
@@ -35,7 +40,7 @@ internal sealed interface NonRetryAbleError : EventUploadError
35
40
*
36
41
* @property responseCode The HTTP response code associated with the error, if available.
37
42
*/
38
- internal sealed class RetryAbleEventUploadError (open val responseCode : Int? = null ) : RetryAbleError {
43
+ internal sealed class RetryAbleEventUploadError (override val responseCode : Int? = null ) : RetryAbleError {
39
44
40
45
/* *
41
46
* `ErrorRetry` represents a retry able error with a specific HTTP response code.
@@ -61,7 +66,7 @@ internal sealed class RetryAbleEventUploadError(open val responseCode: Int? = nu
61
66
* @property ERROR_404 An error indicating that the resource was not found (e.g., the source is disabled).
62
67
* @property ERROR_413 An error indicating that the payload size exceeds the maximum allowed limit.
63
68
*/
64
- internal enum class NonRetryAbleEventUploadError (val responseCode : Int ) : NonRetryAbleError {
69
+ internal enum class NonRetryAbleEventUploadError (override val responseCode : Int ) : NonRetryAbleError {
65
70
66
71
ERROR_400 (responseCode = HTTP_400 ),
67
72
ERROR_401 (responseCode = HTTP_401 ),
@@ -93,22 +98,11 @@ internal fun NetworkResult.toEventUploadResult(): EventUploadResult {
93
98
}
94
99
}
95
100
96
- /* *
97
- * Extension function that retrieves the response code from a RetryAbleError.
98
- * @return The HTTP response code associated with this error, or null if not available.
99
- */
100
- internal fun EventUploadError.getResponseCode (): Int? {
101
- return when (this ) {
102
- is RetryAbleEventUploadError -> this .responseCode
103
- is NonRetryAbleEventUploadError -> this .responseCode
104
- }
105
- }
106
-
107
101
/* *
108
102
* Extension function that formats the error's response code as a message string.
109
103
* @return A string representation of the response code, or "Not available" if the code is null.
110
104
*/
111
105
internal fun EventUploadError.formatResponseCodeMessage (): String {
112
- val responseCode = this .getResponseCode() ? : " Not available"
106
+ val responseCode = this .responseCode ? : " Not available"
113
107
return " Response code: $responseCode "
114
108
}
0 commit comments