How to check database exception before Application Launch |
Hi,
I've completed developing a Restful API with CI4. Just wondering how can we throw a custom message when the database connection cannot be created, or when it's temporarily lost?
Currently, there is no suitable tool for assigning custom handlers.
But there are several options. 1. You can create file app/Views/errors/html/error_8.php 8 - EXIT_DATABASE constant. This file will be used as a template for the DatabaseException. 2. You can create your own exception handler class by extending CodeIgniter\Debug\Exceptions::class. And overriding the Services::exceptions() factory.
(08-18-2022, 10:00 AM)iRedds Wrote: 1. You can create file app/Views/errors/html/error_8.php This is a bug, and it will not work in v4.3. See https://github.com/codeigniter4/CodeIgniter4/pull/6228
8 is not a HTTP status code. The error_*.php is for the HTTP status code.
It feels like we shot ourselves in the foot with this PR.
Now the only way to handle exceptions custom is to modify CodeIgniter\Debug\Exceptions::class. |
Welcome Guest, Not a member yet? Register Sign In |