Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResponseConverter ignored for suspend functions #23

Closed
DanielNovak opened this issue Aug 5, 2022 · 3 comments
Closed

ResponseConverter ignored for suspend functions #23

DanielNovak opened this issue Aug 5, 2022 · 3 comments

Comments

@DanielNovak
Copy link

The suspend API functions ignore any defined ResponseConverters - is that by design? A look into the source code confirms this, only the non-suspend code in KtorfitClient.request uses getResponseConverters().

*(I created a similar GH issue before and I closed it because it contained a lot of other noise)

@DatL4g
Copy link
Contributor

DatL4g commented Aug 6, 2022

I would like to use my ResponseConverter for suspend functions as well.

An exmaple interface looks something like this:

interface Example {
    @GET("test")
    suspend fun getTest(): ApiResponse<String>
}

And my "possible" suspend ResponseConverter like this:

class ApiResponseConverter : ResponseConverter {
    override fun supportedType(returnTypeName: String): Boolean {
        return returnTypeName == "com.example.ApiResponse"
    }

    override suspend fun <PRequest : Any> wrapResponse(
        returnTypeName: String,
        requestFunction: suspend () -> Pair<TypeInfo, HttpResponse>
    ): Any {
        val (info, response)
        return ApiResponse.create(response)
    }
}

The wrapResponse should be a suspend function as well then, so the best thing would be separate class like SuspendResponseConverters I think.

Or the wrapResponse is always a suspend function, not sure if this is possible.

@Foso
Copy link
Owner

Foso commented Aug 22, 2022

@DanielNovak with beta11 it should work now with SuspendResponseConverter

@Foso
Copy link
Owner

Foso commented Aug 25, 2022

I close this issue, if it's still relevant, fell free to reopen it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants