question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to view custom 404 page

See original GitHub issue

Hi, can anyone point me how to view my custom 404 page. I searched and tried implementing ExceptionMapper<RuntimeException> but this did not work. I’m using 0.8.1 version

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
michaelkrnaccommented, Mar 23, 2017

Thanks a lot. Works for me.

  1. Add to XYZconfig.yml
server:
  registerDefaultExceptionMappers: false
  1. Add to XYZApplication.java
    @Override
    public void run(CertConfiguration configuration, Environment environment) {
    	
        // init Error pages
    	 final ErrorPageErrorHandler epeh = new ErrorPageErrorHandler();
         // 400 - Bad Request, leave alone
         epeh.addErrorPage(401, "/error/general-error");
         epeh.addErrorPage(402, "/error/general-error");
         epeh.addErrorPage(403, "/error/403");
         epeh.addErrorPage(404, "/error/404");
         epeh.addErrorPage(405, 499, "/error/general-error");
         epeh.addErrorPage(500, 599, "/error/general-error");
         environment.getApplicationContext().setErrorHandler(epeh);
         environment.getAdminContext().setErrorHandler(epeh);
         
         ErrorResource  errorResource = new ErrorResource();
         environment.jersey().register(errorResource);
  1. Add to ErrorResource.java
@Path("/error")
public class ErrorResource {

    public ErrorResource () {
    }

    @Path("404")
    @GET
    @Timed
    @Produces(MediaType.TEXT_HTML)
    public Response error(){
        return Response.status(404).entity(new ErrorView()).build();
    }

Works with assets and API. So maybe this issue can be closed?

2reactions
arteamcommented, Mar 22, 2017

Have you tried to set up your API on a different path, so JsonProcessingExceptionMapper doesn’t kick in? It can be done with the rootPath parameter in the YML config. Another option is to try to disable default exception mappers by setting the registerDefaultExceptionMappers parameter to false.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django, creating a custom 500/404 error page - Stack Overflow
Under your main views.py add your own custom implementation of the following two views, and just set up the templates 404.html and 500.html...
Read more >
A Beginners Guide to Custom 404 Pages - LCN.com
Customise the error page to make it resemble the other pages of the site. Provide a site search option or a site map...
Read more >
How to Create a Great Custom 404 Error Page (with Examples)
If you have to configure your webserver to show custom error page content, an easy way to generate HTML for the error page...
Read more >
Custom 404 Error Page Test - SEO Site Checkup
This SEO test will check if your website is using a custom 404 error page. By creating a custom 404 error page, you...
Read more >
Django: Customize 404 Error Page - Level Up Coding
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found