Japid icon indicating copy to clipboard operation
Japid copied to clipboard

How to override 404 and 500 pages using japid ?

Open PerfectCarl opened this issue 12 years ago • 1 comments

Play lets us override the default page hander for 404 and 500 errors.

views/errors/404.html

<!DOCTYPE html>

<html>
    <head>
        <title>Not found</title>
        <meta http-equiv="Content-Type" content="text/html; charset=${_response_encoding}"/>    
    </head>
    <body>
        #{if play.mode.name() == 'DEV'}
            #{404 result /}
        #{/if}
        #{else}
            <h1>Not found</h1>
            <p>
                ${result.message}
            </p>
        #{/else}
    </body>
</html>

views/errors/500.html

<!DOCTYPE html>

<html>
    <head>
        <title>Application error</title>
        <meta http-equiv="Content-Type" content="text/html; charset=${_response_encoding}"/>    
    </head>
    <body>
        #{if play.mode.name() == 'DEV'}
            #{500 exception /}
        #{/if}
        #{else}
            <h1>Oops, an error occured</h1>
            #{if exception instanceof play.exceptions.PlayException}
                <p>
                    This exception has been logged with id <strong>${exception.id}</strong>.
                </p>
            #{/if}
        #{/else}
    </body>
</html>

What is the japid way to do it ?

PerfectCarl avatar Oct 21 '13 10:10 PerfectCarl

One way is to change the default 404 page to refer to a japid version, eg: (in app/views/errors/404.html)

<html>
    <head>
        <title>Not found</title>
    </head>
    <body>
        #{if play.mode.name() == 'DEV'}
            #{404 result /}
        #{/if}
        #{else}
        ${cn.bran.play.JapidPlayRenderer.renderWith("japidviews.error404").raw()}
        #{/else}
    </body>
</html>

Then do whatever you want with an Japid based "error404.html" in you japidviews folder.

The above example let your Japid 404 page to handle 404 in prod mode.

branaway avatar Oct 21 '13 11:10 branaway