Skip to content

Commit

Permalink
Improve converter error handling #389
Browse files Browse the repository at this point in the history
  • Loading branch information
Foso committed Oct 8, 2023
1 parent 000d475 commit d3130c1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
15 changes: 15 additions & 0 deletions ktorfit-lib-common/api/android/ktorfit-lib-common.api
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,28 @@ public final class de/jensklingenberg/ktorfit/converter/Converter$ResponseConver
}

public abstract interface class de/jensklingenberg/ktorfit/converter/Converter$SuspendResponseConverter : de/jensklingenberg/ktorfit/converter/Converter {
public abstract fun convert (Lde/jensklingenberg/ktorfit/converter/KtorfitResult;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun convert (Lio/ktor/client/statement/HttpResponse;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class de/jensklingenberg/ktorfit/converter/Converter$SuspendResponseConverter$DefaultImpls {
public static fun convert (Lde/jensklingenberg/ktorfit/converter/Converter$SuspendResponseConverter;Lde/jensklingenberg/ktorfit/converter/KtorfitResult;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun getUpperBoundType (Lde/jensklingenberg/ktorfit/converter/Converter$SuspendResponseConverter;ILde/jensklingenberg/ktorfit/internal/TypeData;)Lde/jensklingenberg/ktorfit/internal/TypeData;
}

public abstract interface class de/jensklingenberg/ktorfit/converter/KtorfitResult {
}

public final class de/jensklingenberg/ktorfit/converter/KtorfitResult$Failed : de/jensklingenberg/ktorfit/converter/KtorfitResult {
public fun <init> (Ljava/lang/Throwable;)V
public final fun getThrowable ()Ljava/lang/Throwable;
}

public final class de/jensklingenberg/ktorfit/converter/KtorfitResult$Success : de/jensklingenberg/ktorfit/converter/KtorfitResult {
public fun <init> (Lio/ktor/client/statement/HttpResponse;)V
public final fun getResponse ()Lio/ktor/client/statement/HttpResponse;
}

public abstract interface class de/jensklingenberg/ktorfit/converter/SuspendResponseConverter : de/jensklingenberg/ktorfit/converter/request/CoreResponseConverter {
public abstract fun wrapSuspendResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
Expand Down
15 changes: 15 additions & 0 deletions ktorfit-lib-common/api/jvm/ktorfit-lib-common.api
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,28 @@ public final class de/jensklingenberg/ktorfit/converter/Converter$ResponseConver
}

public abstract interface class de/jensklingenberg/ktorfit/converter/Converter$SuspendResponseConverter : de/jensklingenberg/ktorfit/converter/Converter {
public abstract fun convert (Lde/jensklingenberg/ktorfit/converter/KtorfitResult;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun convert (Lio/ktor/client/statement/HttpResponse;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class de/jensklingenberg/ktorfit/converter/Converter$SuspendResponseConverter$DefaultImpls {
public static fun convert (Lde/jensklingenberg/ktorfit/converter/Converter$SuspendResponseConverter;Lde/jensklingenberg/ktorfit/converter/KtorfitResult;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun getUpperBoundType (Lde/jensklingenberg/ktorfit/converter/Converter$SuspendResponseConverter;ILde/jensklingenberg/ktorfit/internal/TypeData;)Lde/jensklingenberg/ktorfit/internal/TypeData;
}

public abstract interface class de/jensklingenberg/ktorfit/converter/KtorfitResult {
}

public final class de/jensklingenberg/ktorfit/converter/KtorfitResult$Failed : de/jensklingenberg/ktorfit/converter/KtorfitResult {
public fun <init> (Ljava/lang/Throwable;)V
public final fun getThrowable ()Ljava/lang/Throwable;
}

public final class de/jensklingenberg/ktorfit/converter/KtorfitResult$Success : de/jensklingenberg/ktorfit/converter/KtorfitResult {
public fun <init> (Lio/ktor/client/statement/HttpResponse;)V
public final fun getResponse ()Lio/ktor/client/statement/HttpResponse;
}

public abstract interface class de/jensklingenberg/ktorfit/converter/SuspendResponseConverter : de/jensklingenberg/ktorfit/converter/request/CoreResponseConverter {
public abstract fun wrapSuspendResponse (Lde/jensklingenberg/ktorfit/internal/TypeData;Lkotlin/jvm/functions/Function1;Lde/jensklingenberg/ktorfit/Ktorfit;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ interface ExampleApi {
suspend fun getUser(): Response<User>

@GET("example.json")
suspend fun getUserMy(): MyOwnResponse<User>
suspend fun getUserResponse(): MyOwnResponse<User>
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ val userKtorfit = ktorfit {
converterFactories(
FlowConverterFactory(),
MyOwnResponseConverterFactory(),
UserFactory(), CallConverterFactory()
UserFactory(),
CallConverterFactory()
)
}

Expand All @@ -59,7 +60,7 @@ fun main() {

runBlocking {

val user = userKtorfit.create<ExampleApi>().getUserMy()
val user = userKtorfit.create<ExampleApi>().getUserResponse()

when (user) {
is MyOwnResponse.Success -> {
Expand Down

0 comments on commit d3130c1

Please sign in to comment.