Skip to content

Commit

Permalink
Fix sample code for SuspendResponseConverter (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadFakhraee authored Feb 4, 2025
1 parent cb314d8 commit d6b9dcb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions docs/converters/suspendresponseconverter.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ class MyOwnResponseConverterFactory : Converter.Factory{
if(typeData.typeInfo.type == MyOwnResponse::class) {

return object : Converter.SuspendResponseConverter<HttpResponse, Any> {
override suspend fun convert(response: HttpResponse): Any {
return try {
MyOwnResponse.success(response.body(typeData.typeArgs.first().typeInfo))
} catch (ex: Throwable) {
MyOwnResponse.error(ex)
override suspend fun convert(result: KtorfitResult): Any {
return when (result) {
is KtorfitResult.Failure -> {
MyOwnResponse.error(result.throwable)
}

is KtorfitResult.Success -> {
MyOwnResponse.success(result.response.body(typeData.typeArgs.first().typeInfo))
}
}
}
}
Expand Down

0 comments on commit d6b9dcb

Please sign in to comment.