`setErrorParameter` of error view with `HasErrorParameter<NotFoundException>` called for non-HTML requests
See original GitHub issueDescription of the bug / feature
If a Vaadin 14 application contains a class that implements HasErrorParameter<NotFoundException>
, the setErrorParameter
method gets invoked for any request that returns a 404 error, even for e.g. image requests (when the requested image is missing).
Minimal reproducible example
PageNotFoundView.java
:
@ParentLayout(MainLayout.class)
public class PageNotFoundView extends VerticalLayout implements HasErrorParameter<NotFoundException> {
@Override
public int setErrorParameter(BeforeEnterEvent event, ErrorParameter<NotFoundException> parameter) {
add(new Span("Oh no, not found"));
return 404;
}
}
OtherView.java
:
Image image = new Image("not_found.jpeg", "alt");
add(image);
Expected behavior
setErrorParameter
doesn’t get invoked when navigating into OtherView
Actual behavior
setErrorParameter
gets invoked, even though the PageNotFoundView
is never displayed in the UI. The request for the image also gets a text/html
response, which is against the request’s accept string.
Versions:
- Vaadin / Flow version: 14.5.4
- Java version: 11
- OS version: Windows
- Browser version (if applicable): n/a
- Application Server (if applicable): Spring Boot / Tomcat (n/a)
- IDE (if applicable): n/a
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (11 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In which browser is that? I tested with Chrome, where it seems to only vary based on where the URL is used but not based on the contents of the URL.
No matter what URL prefix I use (I tested
missing.html
,missing.jpg
andmissing.js
), I always get the sameAccept
header based on where I use the URL.Accept
value<iframe>
text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
<img>
image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8
<link rel="stylesheet">
text/css,*/*;q=0.1
Scripts and webfonts are indeed difficult to distinguish since at least my Chrome requests those as
*/*
.We don’t need to have perfect logic for when to create an UI instance and when not, but the more cases we can avoid confusion, the better.
text/html
in the group with highest priority should certainly cause a UI to be created.text/html
at a lower priority, or with only*/*
as the only value.text/html
or if it has*/*
only to supplement some more specific request.This ticket/PR has been released with Vaadin 23.0.2.