-1

Below I have some code within my bootstrap.php file that should display a pretty error page whenever a page within the website can't resolve. However, the line echo 'Todo: Friendly error page'; keeps displaying before Bugsnag can get the error information. Any assistance or insight would be appreciated.

/**
 * Register the error handler
 */
$whoops = new \Whoops\Run;
if ($is_prod) {
    $whoops->pushHandler(function($e){
        echo 'Todo: Friendly error page';
    });
    $bugsnag = Bugsnag\Client::make("61a075bcdc8317eab9ed0ab86aada144");
    Bugsnag\Handler::register($bugsnag);
} else {
    $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
}
$whoops->register();
Jonathan Rauscher
  • 147
  • 1
  • 1
  • 15

1 Answers1

1

This is because only one error handler can bind to the application and currently it's binding to whoops therefore bugsnag never gets called.

I'd recommend using a single error handler and then calling bugsnag from there, we can do this like so.

$whoops = new \Whoops\Run;

if ($is_prod) {
    $bugsnag = Bugsnag\Client::make("61a075bcdc8317eab9ed0ab86aada144");

    $whoops->pushHandler(function($e) use($bugsnag) {
        $bugsnag->notifyException($e);
        echo 'Todo: Friendly error page';
    });
} else {
    $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
}
Matt Bucci
  • 2,100
  • 2
  • 16
  • 22