Custom page error connection database

Custom page error connection database

by Brian Palma -
Number of replies: 3

Hi

I work with Moodle 3.7.1 and I want to customize the error page (see above) or other option is redirect to other error page. How can I do this?


Thanks

Average of ratings: -
In reply to Brian Palma

Re: Custom page error connection database

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

There is no way to fully customise this without changing core Moode code. (Because this happens so early in the process of Moodle starting up, none of the standard Moodle customisation options will work yet.)

You only need to add a little bit in lib/dmllib.php. Then you can put the code to do whatever error handling you want in local/error/lib.php (or whatever other file you want to use.)

    try {
        $DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, $CFG->dboptions);
    } catch (moodle_exception $e) {
// ou-specific begins #813
        require_once(__DIR__ . '/../local/error/lib.php');
        ou_http_error('Database connection failed.');
// ou-specific ends #813

Acutally, there is one way Moodle core could support this: We coudl allow people to define things like this in config.php:

$CFG->dbconnecterrorhander = 'ou_http_error';
$CFG->dbconnecterrorhanderfile = 'local/error/lib.php';

Do other peple customise that error page like this? Should we open a MDL for adding those hooks?

In reply to Tim Hunt

Re: Custom page error connection database

by Jon Bolton -
Picture of Particularly helpful Moodlers Picture of Testers
Oh, I definitely changed the text on that page on one of my sites but I must have edited the code directly.

Yes, custom hooks would be very useful smile