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

Add awaitExchangeOrNull extension function to reactive webclient #26778

Closed
wants to merge 1 commit into from

Conversation

gabrielerzinger
Copy link
Contributor

Background

When using the awaitExchange extension function on a Kotlin project, I've missed the presence of a awaitExchangeOrNull function, that would receive a function returning T?. I've added it to my project, but I think it would be nice to have it on the lib aswell, since I believe it is a usefull extension function.

Changes

I've simple added a new extension function awaitExchangeOrNull and two test scenarios.

This is my first time attempting to contribute to an open source repository, so, feel free to correct me or suggest changes, I will gladly adhere to suggestions. And let me know if this isn't desired.

@pivotal-issuemaster
Copy link

@gabrielerzinger Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@gabrielerzinger Thank you for signing the Contributor License Agreement!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 8, 2021
@gabrielerzinger
Copy link
Contributor Author

@sdeleuze i saw that you were the one who recently changed those files, do you think this makes sense?

@sdeleuze sdeleuze self-requested a review April 13, 2021 14:57
@sdeleuze
Copy link
Contributor

Thanks for your contribution, I need to have a deeper look but it seems to make sense indeed.

@sdeleuze sdeleuze added this to the 5.3.7 milestone Apr 13, 2021
@sdeleuze sdeleuze added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 13, 2021
@jhoeller jhoeller modified the milestones: 5.3.7, 5.3.8 May 11, 2021
@rgmz
Copy link

rgmz commented May 31, 2021

Hey @sdeleuze, are there any updates or blockers on this?

To expand on @gabrielerzinger's use-case, prior to 5.2 (when awaitExchange() was deprecated), it was possible to write the following code:

// Check whether the role already exists.
val existing = client.get().uri("/api/roles/${role.id}")
    .awaitExchange()
    .let {
        when (val status = it.statusCode()) {
            HttpStatus.OK -> it.awaitBodyOrNull<Role>()
            HttpStatus.NOT_FOUND -> null
            else -> {
                val resp = it.awaitBodyOrNull<String>()
                throw IllegalStateException("Unexpected response from '/api/roles/${role.id}': status=$status, body=$resp")
            }
        }
    }

Because awaitExchange { } doesn't have a nullable counterpart, it's not possible to represent the same logic. I was actually in the midst of upgrading a project when I came across this issue.

Let me know if there's any way I can help get this merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants