If a website writes errors to the user then this is a very good idea. A characteristic of scripted websites I think? This one is written in php. I am actually surprised Wordpress as one of the most used frameworks in the world has not a more graceful handling of this situation.
You don't need to show the user errors for this approach to work.
At a client of mine, the load balancer is setup with a customer friendly fallback page to present, in cases where none of the backend servers are available. This is used in instances where something technical goes wrong, and also during planned outages for things like DB schema migrations (although these tend to take just a few seconds).
We then have monitoring setup to notify us if the website does not include some text that is always included on the working site, but is not included in the maintenance page.
- Customer gets a friendly page telling them the site is unavailable, regardless of the cause; and
- We get notifications any time the production environment isn't publicly available.
Warning: mysqli_real_connect(): (HY000/2002): Connection refused in /var/www/html/wp-includes/class-wpdb.php on line 1987
Connection refused Error establishing a database connection