sealed class Results { class Success(val response: T): Results() class Failure(val message: String, val serverError: ServerError?): Results() object NetworkError: Results() } class ResultsCallAdapterFactory private constructor() : CallAdapter.Factory() { companion object { @JvmStatic fun create() = ResultsCallAdapterFactory() } override fun get(returnType: Type, annotations: Array, retrofit: Retrofit): CallAdapter<*, *>? { return try { val enclosedType = returnType as ParameterizedType val responseType = getParameterUpperBound(0, enclosedType) val rawResultType = getRawType(responseType) val delegate: CallAdapter = retrofit.nextCallAdapter(this,returnType,annotations) as CallAdapter if(rawResultType != Results::class.java) null else { object: CallAdapter{ override fun adapt(call: Call): Any { val response = delegate.adapt(call) //What should happen here? return response } override fun responseType(): Type { return delegate.responseType() } } } } catch (e: ClassCastException) { null } } }