Blog» Custom fatal error message for eZ Publish (legacy)

Custom fatal error message for eZ Publish (legacy)


Until some time ago, it was necessary to hack the eZ Publish legacy kernel in order to customize its generic error message, "Fatal error: The web server did not finish its request". This error occurs on all eZ Publish installations whenever there is an HTTP 500 status server error. It is a very common error; some examples of how it's triggered include: trying to access the value of a non-existent object attribute; the use of a non-existent PHP class or function; and too much memory usage.

Now, since this pull request from Mugo has been merged to the eZ Publish kernel, we have made it possible to customize the error page without hacking the kernel. In this post I will show you the new standard way to do this with a simple INI setting and your own PHP function.

Here's the default HTTP 500 error message:

 

In order to use your own function, you need to override the global error.ini file (settings/override/error.ini.append.php), and define the following setting:

[ErrorSettings-kernel]
FatalErrorHandler=CustomFatalErrorHandlerClass::FatalErrorHandlerFunction

CustomFatalErrorHandlerClass can be any class, and FatalErrorHandlerFunction must be a public static function of the specified class.

class CustomFatalErrorHandlerClass
{
    public static function FatalErrorHandlerFunction()
    {
        header("HTTP/1.1 500 Internal Server Error");
        echo '<strong>Sorry!</strong> Something has gone wrong. We have logged the error but feel free to <a href="/contact">contact us</a>';
        eZDisplayResult(null);
    }
}

That's all you need to customize the error page!

It is also possible to use an eZ Publish template.

class CustomFatalErrorHandlerClass
{
    public static function FatalErrorHandlerFunction()
    {
        header("HTTP/1.1 500 Internal Server Error");
        $tpl = eZTemplate::factory();
        echo $tpl->fetch( 'design:error500.tpl' );
        eZExecution::cleanExit();
    }
}

This way, you have full control over the style of the error page. You can add images and use your own stylesheet, just like any other page on your site.


Join our mailing list for news, events, tips, and tools

Related Blog Posts

"Sort by language" filter in eZ Publish

Multi-language sites often have a set of base rules and then edge cases for different parts of the site. For example, on the French version of the site...

Read more »

Reading object states in eZ Publish 5

Object states are used in many ways in eZ Publish, from workflows to menu management to controlling SEO tags. In eZ Publish 5, object state information...

Read more »

Command line tool for eZ Publish, called "eep"

Mugo has a tool that we use internally to help with the main aspects of a developer's life: development, debugging and maintenance. The tool is called "...

Read more »

Comments

blog comments powered by Disqus

Hi, we're Mugo Web - Nice to meet you!

We're a group of web experts who solve complex web problems.

Learn more about us »

Search


Categories


Yes - we can do that.

Many years of experience with complex websites allows us to offer total solutions.

Learn more about what we can do »

We love our clients (and they love us too)

We've solved problems across North America and around the world.

Learn more about what we've done »

We tweet too

Follow us on Twitter for the latest Mugo happenings

mugo twitter page @mugo

© 2008 - 2019 Mugo Web. All rights reserved.