codin/fault

Extendable error handler

1.2.0 2022-12-12 10:34 UTC

This package is auto-updated.

Last update: 2024-11-12 16:16:23 UTC


README

version workflow license

Simple error exception handler

Usage

$error = new Codin\Fault\ErrorHandler();

if ('cli' === php_sapi_name()) {
    $error->attach(new Codin\Fault\Handler\ConsoleHandler());
} else {
    $error->attach(new Codin\Fault\Handler\WebHandler($debug = true));
}

$error->register();

Example with monolog+sentry

$options = [
    'dsn' => '...',
    'environment' => '...',
];
$builder = new Sentry\ClientBuilder(new Sentry\Options($options));
$sentry = new Sentry\State\Hub($builder->getClient());

$logger = new Logger('app');
$logger->pushHandler(new Sentry\Monolog\Handler($sentry, Logger::NOTICE));

$error = new Codin\Fault\ErrorHandler();
$error->attach(new Codin\Fault\Handler\PsrHandler($logger));
$error->register();