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

Whitelabel error page doesn't display when deployed to Tomcat server #684

Closed
ukdave opened this issue Apr 16, 2014 · 5 comments
Closed

Whitelabel error page doesn't display when deployed to Tomcat server #684

ukdave opened this issue Apr 16, 2014 · 5 comments
Labels
type: bug A general bug
Milestone

Comments

@ukdave
Copy link

ukdave commented Apr 16, 2014

I've got a basic spring boot webapp and I'm trying to create a customised error page for it.

I'm using spring-boot-actuator so I've got its default whitelabel error page and have successfully customised it by creating my own error.html page. This is working nicely when running with the embedded Tomcat container - if one of my controllers throws an exception (e.g. DataAccessException) then my custom error page gets displayed. However, when I deploy my app to a Tomcat server I get the default Tomcat error page showing the full stack trace.

I've been trying to trace what's going on using the debugger in STS and I've found the ErrorPageFilter (which only seems to be present when running on the Tomcat server) is correctly handling the exception and forwarding the request to the error controller. However tracing further I eventually get to the invoke method of org.apache.catalina.valves.ErrorReportValve which seems to then reset the response.

I'm using Spring Boot 1.0.1.RELEASE and Apache Tomcat 7.0.53.

@dsyer dsyer closed this as completed in 0d44e6e Apr 16, 2014
@dsyer dsyer added the bug label Apr 16, 2014
@dsyer dsyer added this to the 1.0.2 milestone Apr 16, 2014
gigfork pushed a commit to boostrack/spring-boot that referenced this issue Apr 21, 2014
Otherwise Tomcat will go ahead and uncommit it and handle it again
in the ErrorReportValve (duh!)

Fixes spring-projectsgh-684
@hoserdude
Copy link
Contributor

Saw this as well - after the fix the custom page comes back as a 200, should the ErrorPageFilter also set the Response status to 500 (or whatever?). I added response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); just before the wrapped.sendError(500, ex.getMessage()) call and that seemed to do the trick. Alternatively the BasicErrorController could do the equivalent before it returns the view. What do you guys think?

@dsyer
Copy link
Member

dsyer commented Apr 23, 2014

I assume in a JAR deployment you get a 500 (in which case if you make a change it should go in the filter)?

See also #538 (which when fixed will include generic error handling for all >=400 errors), which is down for 1.1 because it's quite a big change. Maybe better to wait till that is finished before changing anything?

@hoserdude
Copy link
Contributor

Sounds good, my custom ErrorController takes care of this for now.

mdeinum pushed a commit to mdeinum/spring-boot that referenced this issue Jun 6, 2014
Otherwise Tomcat will go ahead and uncommit it and handle it again
in the ErrorReportValve (duh!)

Fixes spring-projectsgh-684
@sarpk
Copy link

sarpk commented Sep 27, 2016

I still have the same issue that hoserdude had in 2014.

The bad thing about hoserdude's solution is say if the response was something else apart from 500 then you would still return 500. So I want to prevent that happening. ie not much point showing 500 error when the actual response is 404.

@dsyer
Copy link
Member

dsyer commented Sep 27, 2016

Thanks for your interest. It almost never helps to comment on an issue that was closed as resolved 2 years ago. It's unlikely that you are using the same code as was current then, but if you are just upgrade. Otherwise I would recommend opening a new issue or asking a question on stackoverflow if it's about usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants