package io.apibuilder.app import com.jakewharton.retrofit2.adapter.rxjava2.HttpException import io.reactivex.Single import java.net.SocketTimeoutException import kotlin.Int import kotlin.Pair import kotlin.String import kotlin.Throwable /** * Utility data class to combine a call with its response code and its error responses * This code was generated by [models.generator.kotlin.KotlinGenerator] */ data class ApiNetworkCallResponse( val networkSingle: Single>, val toError: (Throwable) -> E ) /** * Either type that combines CommonNetworkErrors with network errors for a specific call (as defined * in apibuilder.json) * This code was generated by [models.generator.kotlin.KotlinGenerator] */ sealed class EitherCallOrCommonNetworkError { data class CallError( val error: C ) : EitherCallOrCommonNetworkError() data class CommonNetworkError( val error: CommonNetworkErrors ) : EitherCallOrCommonNetworkError() } /** * Common generic errors that are expected to happen are not defined in apibuilder.json * This code was generated by [models.generator.kotlin.KotlinGenerator] */ sealed class CommonNetworkErrors { data class ServerError( val httpCode: Int, val responseDump: String ) : CommonNetworkErrors() data class ServerTimeOut( val responseDump: String ) : CommonNetworkErrors() data class UnknownNetworkError( val httpCode: Int, val responseDump: String ) : CommonNetworkErrors() companion object { fun processCommonNetworkError(t: Throwable): CommonNetworkErrors = when (t) { is HttpException -> { val body: String? = t.response().errorBody()?.string() when (t.code()) { in 500..599 -> ServerError(t.code(), t.message()) else -> UnknownNetworkError(t.code(), t.message()) } } is SocketTimeoutException -> ServerTimeOut( t.message?: "Server Timeout Error, t.message() was null" ) else -> UnknownNetworkError( -1, t.message?: "Unknown Network Error, t.message() was null" ) } } }