Is it possible to route to a nice "Site is currently offline" error page if there is an issue connecting to the database?

Currently you'll see something like the message below which isn't very customer friendly.

An exception has been thrown during the rendering of a template ("Craft can’t connect to the database with the credentials in craft/config/db.php.") 
  • 1
    The part about this that always bugs me the most is the weird non-apostrophe in can’t.
    – Lindsey D
    Dec 2 '14 at 17:48

On a default Craft install if I'm logged out and hit the front-end of the site with purposefully messed up database credentials, I get a nicely styled Craft 404 page if there is no craft/templates/404.html and a front-end 404 page if there is.

I believe the issue is that you've got your own front-end 404 template that's also trying to access the database and it can't.

So basically the first error is thrown (can't access the database), then another error happens (I really can't access the database) when trying to tell you about the first error.

By this point, Yii thinks the error has already been handled, so it falls back to CApplication->displayException(). I assume in this case, some content header or encoding isn't set properly and you see the garbled ’ character.

So until/if we can think of a way to guard against this scenario, your best bet is to make sure that your 404 template isn't triggering a database call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.