Skip to content

Instantly share code, notes, and snippets.

@thomaskioko
Created July 25, 2023 14:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thomaskioko/1049ca4eb8e910b2751c6d5f1b56f2eb to your computer and use it in GitHub Desktop.
Save thomaskioko/1049ca4eb8e910b2751c6d5f1b56f2eb to your computer and use it in GitHub Desktop.
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