flow: Status returned by HasErrorParameter#setErrorParameter is ignored.
Description of the bug
I just downloaded sample project from start.vaadin.com and added RouteNotFoundView almost same as in documentation.
public class RouteNotFoundView extends Div implements HasErrorParameter<NotFoundException> {
@Override
public int setErrorParameter(BeforeEnterEvent event, ErrorParameter<NotFoundException> parameter) {
getElement().setText("Cannot not navigate to '"
+ event.getLocation().getPath()
+ "'");
return HttpServletResponse.SC_NOT_FOUND;
}
}
But it still returns HTTP status 200 and ignores HttpServletResponse.SC_NOT_FOUND
$ wget http://localhost:8080/notFound
--2022-04-05 14:13:51-- http://localhost:8080/notFound
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8080... connected.
HTTP request sent, awaiting response... 200
Length: 3665 (3,6K) [text/html]
Saving to: ‘notFound’
notFound 100%[====================================================================================================>] 3,58K --.-KB/s in 0s
2022-04-05 14:13:51 (344 MB/s) - ‘notFound’ saved [3665/3665]
Expected behavior
Status 404 or any other status, which set as return value should be returned instead.
Minimal reproducible example
- Download sample project from start.vaadin.com
- Add
RouteNotFoundViewgiven at bug description. - Run project
- visit any non-existent route
Versions
- Vaadin / Flow version: 23.0.3
- Java version: 17.0.3
- OS version: Linux Manjaro, kernel 5.16.14-1-MANJARO
- Browser version (if applicable): Firefox 98.0.2
- Application Server (if applicable): the one goes with Spring Boot
- IDE (if applicable): Intelij IDEA
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 5
- Comments: 17 (11 by maintainers)
Commits related to this issue
- fix: Use correct view when using eagerServerLoad Returns 404 for non existant views Helps with #13421 — committed to vaadin/flow by Artur- 4 years ago
- fix: Use correct view when using eagerServerLoad (#14036) * fix: Use correct view when using eagerServerLoad Returns 404 for non-existant views Helps with #13421 — committed to vaadin/flow by Artur- 4 years ago
- fix: Use correct view when using eagerServerLoad (#14036) * fix: Use correct view when using eagerServerLoad Returns 404 for non-existant views Helps with #13421 — committed to vaadin/flow by Artur- 4 years ago
- fix: Use correct view when using eagerServerLoad (#14036) * fix: Use correct view when using eagerServerLoad Returns 404 for non-existant views Helps with #13421 — committed to vaadin/flow by Artur- 4 years ago
- fix: Use correct view when using eagerServerLoad (#14036) * fix: Use correct view when using eagerServerLoad Returns 404 for non-existant views Helps with #13421 (cherry picked from commit 87c220a... — committed to vaadin/flow by Artur- 4 years ago
- fix: Use correct view when using eagerServerLoad (#14036) (CP: 23.0) (#14077) Returns 404 for non-existant views Helps with #13421 — committed to vaadin/flow by vaadin-bot 4 years ago
- fix: Use correct view when using eagerServerLoad (#14036) (CP: 23.1) (#14076) * fix: Use correct view when using eagerServerLoad (#14036) * fix: Use correct view when using eagerServerLoad Retu... — committed to vaadin/flow by vaadin-bot 4 years ago
- fix: Use correct view when using eagerServerLoad (#14036) (CP: 9.0) (#14078) * fix: Use correct view when using eagerServerLoad (#14036) Returns 404 for non-existent views Helps with #13421 ... — committed to vaadin/flow by taefi 4 years ago
I can confirm that with 23.1.3
eagerServerLoadworks as expected and the application behaves as it should again. As Leif already mentioned above, this only works for applications that only use server-side routes.For SpringBoot apps just add
Good point. Checked the code and it seems that we should have a list of client-side routes available both in dev and prod mode. What we don’t currently have is logic to check if a route is found among all the server and client routes, but now I don’t see any technical reason why it could not be added. There is conflict checking on Flow side in
com.vaadin.flow.router.internal.RouteUtil#checkForClientRouteCollisions(com.vaadin.flow.server.VaadinService, java.lang.String...). Maybe we need a new method e.g. inRouteUtilthat would check if the target route exists at all.Also, not sure how this would work with dynamic routes registered during the first UIDL request. In such case we would return 404 for a missing route before the dynamic routes have a chance to be registered, which would be wrong.
@mshabarov FYI: the mentioned workaround to use “vaadin.useDeprecatedV14Bootstrapping=true” has caused multiple reports on discord and stack overflow that it renders the UI twice (see comments above as well) - this should either documented or fixed… because people run into this when migrating from V14
Apart from the bug addressed in #14036, the documentation is currently misleading here to not mention a different behavior with and without
eagerServerLoadenabled. See https://github.com/vaadin/docs/issues/1521