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

onStatus throws away default status handler #23155

Closed
indiv1d opened this issue Jun 19, 2019 · 3 comments
Closed

onStatus throws away default status handler #23155

indiv1d opened this issue Jun 19, 2019 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@indiv1d
Copy link

indiv1d commented Jun 19, 2019

Affects: 5.2.0.M3

Description
Using webflux WebClient i want to override behavior if service returns 404 http code. Documentation says to use onStatus but there is no warning that it will throw away the default handler and i will lose default behavior on 5xx/4xx statuses.
Is it supposed to be like that? If i override one status i must provide handler for other error statuses?

@Override
public ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate,
        Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction) {

    if (this.statusHandlers.size() == 1 && this.statusHandlers.get(0) == DEFAULT_STATUS_HANDLER) {
        this.statusHandlers.clear();
    }
    this.statusHandlers.add(new StatusHandler(statusPredicate,
            (clientResponse, request) -> exceptionFunction.apply(clientResponse)));

    return this;
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 19, 2019
@indiv1d
Copy link
Author

indiv1d commented Jun 19, 2019

I see the solution is to add custom handlers in front of default one and use default as fallback.

@poutsma poutsma self-assigned this Jun 21, 2019
@poutsma poutsma removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 21, 2019
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 21, 2019
@poutsma poutsma added this to the 5.2 RC1 milestone Jun 25, 2019
@rstoyanchev rstoyanchev 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 Jun 25, 2019
@rstoyanchev
Copy link
Contributor

This looks related to #22825.

@poutsma
Copy link
Contributor

poutsma commented Jul 16, 2019

As of a9b3d95, we no longer delete the default error handlers when you add a new one, solving this issue.

Now, we interpret an error handler that returns an empty mono as a signal to return the normal response (and thus override the default error handlers).

@poutsma poutsma closed this as completed Jul 16, 2019
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

No branches or pull requests

4 participants