-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
404 on static resource does not return HTML error page #31569
Comments
@rstoyanchev any chance this can be triaged/checked before 3.2.0 release? |
I've had a look and reproduced the problem. This is an unfortunate consequence of #29491 and #30930 which is really a disconnect between the evolution of error handling and problem details here in Spring Framework, and how things are done in Spring Boot. I'm leaving this issue opened for now to discuss that in the Spring Framework team first, but I think the changes should happen ultimately in Spring Boot. |
Hi Spring Team, Using the global exception handler to handle the
|
Here is a workaround for this issue: declare the following bean in your application: import org.springframework.core.annotation.Order;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.resource.NoResourceFoundException;
@ControllerAdvice
@Order(-1)
class NoResourceFoundExceptionHandler {
@ExceptionHandler(NoResourceFoundException.class)
public final ResponseEntity<Object> handleResourceNotFound(Exception ex) throws Exception {
throw ex;
}
} |
Or alternatively, provide your own @ControllerAdvice
public class ProblemDetailsExceptionHandler extends ResponseEntityExceptionHandler {
@Override
protected ResponseEntity<Object> handleNoResourceFoundException(
NoResourceFoundException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
// If exception handling fails, processing of original exception continues
throw new IllegalStateException();
}
} |
Before RFC 7807 we could not have an opinion in Spring Framework on the format of an error response, and could only have the abstract #29491 and #30930 bring static resource exceptions into the fold, by having those handled within Spring MVC like other internal exceptions. However, |
@bclozel I've applied your proposed workaround today and it seems to resolve all our problems. Thanks for the quick fix. 😄 |
We have a separate info controller that shows the link to the swagger ui. Since Spring Boot 3.2 the 404 error handling is different (see spring-projects/spring-framework#31569), so this is effectively unused.
We have a separate info controller that shows the link to the swagger ui. Since Spring Boot 3.2 the 404 error handling is different (see spring-projects/spring-framework#31569), so this is effectively unused.
Closing this issue in favor of #31936 on the Framework side, spring-projects/spring-boot#33885 and spring-projects/spring-boot#19525 for Spring Boot support. |
With the upgrade to Spring Boot 3.2.0-RC2 I think there is the following regression bug:
When a user visits an application, with ProblemDetail support enabled, with a browser and asking for HTML, then Spring should return the standard HTML error page instead of returning a ProblemDetail JSON or XML when static resource does not exist.
This would particularly be important for applications that both serve a browser frontend as well as a REST API.
Related issues:
NOTE: Attached is an example
sb3-rest-webmvc.zip
The text was updated successfully, but these errors were encountered: