-
-
Save thomaskioko/1049ca4eb8e910b2751c6d5f1b56f2eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class ApiResponse<out T, out E> { | |
/** | |
* Represents successful network responses (2xx). | |
*/ | |
data class Success<T>(val body: T) : ApiResponse<T, Nothing>() | |
sealed class Error<E> : ApiResponse<Nothing, E>() { | |
/** | |
* Represents server errors. | |
* @param code HTTP Status code | |
* @param errorBody Response body | |
* @param errorMessage Custom error message | |
*/ | |
data class HttpError<E>( | |
val code: Int, | |
val errorBody: String?, | |
val errorMessage: String?, | |
) : Error<E>() | |
/** | |
* Represent SerializationExceptions. | |
* @param message Detail exception message | |
* @param errorMessage Formatted error message | |
*/ | |
data class SerializationError( | |
val message: String?, | |
val errorMessage: String?, | |
) : Error<Nothing>() | |
/** | |
* Represent other exceptions. | |
* @param message Detail exception message | |
* @param errorMessage Formatted error message | |
*/ | |
data class GenericError( | |
val message: String?, | |
val errorMessage: String?, | |
) : Error<Nothing>() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment