Jump to content

(Static) Template page for failure to connect to DB


BrendonKoz
 Share

Recommended Posts

Although not frequent, and usually not for very long, databases will experience problems and just not be able to be connected to.

An error message of just "Unable to complete this request due to an error. Error has been logged." just doesn't seem too friendly to visitors.

Perhaps I just haven't seen this (or discovered how to do it), but if it isn't currently an option (or a hook) for this, it'd be a welcomed thing. :) (If there is a way to do this, I apologize...it's sometimes hard to come up with the proper search terms to find results.)

  • Like 4
Link to comment
Share on other sites

I noticed on some installs I sometimes get this a lot:

Unknown User:/?/:ProcessWire Error:Exception: (in /home/aoccons/www/aoc/wire/core/Database.php line 72)

, and have no idea what is causing it. Since it's not happening on other hosts I guess it has to do with the server and mysql. It simply can't connect.

I remember this has come up in the forums some, and I thought it has nothing to do with PW so I don't know if it's possible to do what you suggest.

Link to comment
Share on other sites

I guess I did find the proper forum then. I realize that Processwire uses Exception handling to bubble up error reporting. I'd just hope that, even if there's an error handler for database issues that it (somewhere) has a way to implement this change. I'll have to look around, but I don't know if I'll be able to find anything.

Wishlist! :)

Link to comment
Share on other sites

The error message is intentionally vague because you don't want to reveal anything about the system or what's happening to non administrative users. Detailed error messages are a hackers best friend. :)

If you are a logged-in admin user, then you should get a more detailed error message. Likewise, you can review your /site/assets/logs/errors.txt for more detailed messages. Lastly, you can enter an email address in your /site/config.php ($config->adminEmail) and get error messages emailed to you as they occur.

The one that Soma mentioned sounds unintentionally ambiguous when it shouldn't be, so let me know if you find a way to reproduce it. However, the one BrendonKoz mentioned is very much intentionally vague for security reasons.

Link to comment
Share on other sites

I think what he means is that the error isnt user friendly and may should output a page like the 4o4. Nut that makes sense or if i understand it wrong. After all it an db error that isnt same as a page not found and shouldnt be threated as the page is actually there.

My error message is the one i get per email. And its a db connect error that has nothing to do with pw directly and a problem of the host. Though havent looked or asked the hoster yet. It happens occasionally and we already discussed thsi error in a thread where you said you will provide a better error message. Could be wrong though.

Link to comment
Share on other sites

In broadcasting we did everything we could to avoid leaving the visitor hanging when our data source dried up (the engineer got his kipper tie stuck in the VT, for instance).

Not getting that right and ending up shoving a test card in the viewers face was a near sack-able offence.

In a perfect world, a visitor should get an apology and a static site to play with - perhaps a cached version of part of the site or something. At least enough so they can still read about your world, even if they cannot interact with it.

Sort of a 404 on steroids that is not reliant on the database.

And of course, a nice output for the poor admin somewhere ....

Joss

Link to comment
Share on other sites

I think ryan mentioned that he was working on an uber-cache type module that caches a static-content-only version of pages for high-traffic websites, but equally it could be nice to use this if there is an unexpected error I guess?

As long as the admin is made aware that there was an issue and maybe the end-user gets a message about a page not being as bells-and-whistles as it could be but still showing them the content then that would be quite nice really.

Link to comment
Share on other sites

I think what he means is that the error isnt user friendly and may should output a page like the 4o4. Nut that makes sense or if i understand it wrong. After all it an db error that isnt same as a page not found and shouldnt be threated as the page is actually there.

Yes, sorry for not being clear. Information to developers/administrators is definitely important! I typically check error logs. I could even understand seeing logged in users of the admin group seeing a more descriptive error message (if desirable in the template) than standard site visitors, but what I'm envisioning is basically a custom error page, except obviously not sending 404 headers.

As long as the admin is made aware that there was an issue and maybe the end-user gets a message about a page not being as bells-and-whistles as it could be but still showing them the content then that would be quite nice really.

Exactly. A default splash page might be nice, but being able to customize it to your own site's design, as well as to your audience, would make things so much nicer when the unthinkable (database goes down) might happen. ...unfortunately that "unthinkable" issue does happen to us more frequently than I'd like under our shared hosting plan. Having the ability to display a custom designed page would just make the system that more robust.

Link to comment
Share on other sites

Showing a 404 is exactly what we do when there is a non-recoverable error like this (with guest user). But this is the one scenario where we can't. The 404 is a page like any other in the system, so if the DB is down, then we can't really retrieve anything at all. The DB is a vital organ. The only thing I can think of is that perhaps we could provide some custom predefined error template, perhaps /site/templates/errors/500.php that gets used instead, when present. But you'd have to assume the API was off limits, otherwise you'd potentially start an infinite error loop.

Link to comment
Share on other sites

I suppose that does make sense since a DB error would be a non-recoverable system error. I'd actually think that would make more sense in most cases than a 404 - at least if a page is supposed to exist.

As for the error template - that was basically what I had in mind, yes. I believe that would be perfect. Thank you all for the feedback and discussion!

Link to comment
Share on other sites

As for the error template - that was basically what I had in mind, yes. I believe that would be perfect. Thank you all for the feedback and discussion!

Sounds good, I am putting this in 2.3 and should be on the dev branch later today. It will look for a file /site/templates/errors/500.html and use it when present.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...