Welcome Guest, Not a member yet? Register   Sign In
Exception Handler Event
#1

(This post was last modified: 07-08-2022, 03:40 PM by php_rocs.)

Hi!
I recently got a service called Honeybadger which lets me log exceptions in a really nice format. They don't have a CodeIgniter integration so I'm looking to integrate it myself. I got stuck while looking into how CodeIgniter 4 handles exceptions. I found the "exceptionHandler" function in vendor/codeigniter4/framework/system/Debug/Exception.php which is really close to what I need.  That method's comment states that it "fires an event that allows custom actions to be taken at this point."  While that sounds like exactly what I need, I can't seem to figure out what it means by "fire an event." All I want to do is call a [docs.honeybadger.io/lib/php/integration/other/] Honeybadger method, passing in any exception that happens.
What is this event thing, and how can I hook into that?
Thank you in advance.
Reply
#2

(This post was last modified: 07-08-2022, 05:37 PM by kenjis.)

It seems event means CodeIgniter's Event.
https://codeigniter4.github.io/CodeIgnit...ent-points

But there is no Event Points for it, and there is no code to fire an event in the exceptionHandler() method.

You can extend the Exception class.
See https://codeigniter4.github.io/CodeIgnit...asses.html
Reply
#3

@matjlars I haven’t used HoneyBadger but I use Sentry.io which does the same thing. Their SDK actually registers the listener as an exception handler, so as long as it is loaded you don’t need to do the handling yourself. Check if HoneyBadger has a similar feature. I put my registration in **app/Config/Boot/production.php** to load it early, and because I only want monitoring in production- but you could also load it in Events or Common. 
Here’s what my code looks like: 
PHP Code:
/*
 *---------------------------------------------------------------
 * SENTRY.IO
 *---------------------------------------------------------------
 * Initialize Sentry for exception reporting.
 */
if (getenv('sentry.dsn')) {
    init([
        'dsn'          => getenv('sentry.dsn'),
        'integrations' => [
            new IgnoreErrorsIntegration([
                'ignore_exceptions' => ['CodeIgniter\Exceptions\PageNotFoundException'],
            ]),
        ],
    ]);

Reply




Theme © iAndrew 2016 - Forum software by © MyBB