Welcome Guest, Not a member yet? Register   Sign In
How to check database exception before Application Launch
#1

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?
Reply
#2

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.
Reply
#3

I see.. let me give a try. thanks @iRedds
Reply
#4

(08-18-2022, 10:00 AM)iRedds Wrote: 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.

This is a bug, and it will not work in v4.3.
See https://github.com/codeigniter4/CodeIgniter4/pull/6228
Reply
#5

(This post was last modified: 08-18-2022, 10:13 PM by iRedds.)

@kenjis Why did you need to make a bug? =)
So the only error pattern now is 404?
Reply
#6

8 is not a HTTP status code. The error_*.php is for the HTTP status code.
Reply
#7

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB