swiftyper/emperror-php

Provides an error handler for PHP that can execute a stack of handlers for various purposes.

Maintainers

Package info

github.com/swiftyper-sk/emperror-php

pkg:composer/swiftyper/emperror-php

Transparency log

Statistics

Installs: 59

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-08-14 18:18 UTC

This package is auto-updated.

Last update: 2026-08-14 20:10:57 UTC


README

EMPERROR logo

Emperror PHP

PHP error catcher and handler for swiftyper.sk.

Emperror catches PHP exceptions, errors, warnings, and notices.

๐Ÿ“– Requirements

  • PHP 7.2 or higher
  • PHP extensions: curl, json
  • Composer is required for installation

๐Ÿ“ฆ Installing

$ composer require swiftyper/emperror-php

โšก๏ธ Quick Start

Configuration

\Swiftyper\Emperror::setup([
    'apiKey' => 'your api key'
]);
\Swiftyper\Emperror::get()
    ->setUser([
        'name' => 'user name',
        'photo' => 'user photo',
    ])
    ->setContext([
        'orderId' => 1234,
    ]);

Send events and exceptions manually

Use sendException() to send any caught exception:

try {
    throw new Exception("Payment processing error", 1);
} catch (Exception $e) {
    \Swiftyper\Emperror::get()->sendException($e);
}

Use sendMessage() to send a plain message with optional context - ideal for logs, notices, or anything that isn't an exception:

\Swiftyper\Emperror::get()->sendMessage('Payment webhook received twice', [
    'webhookId' => $webhookId,
]);

Use sendEvent() when you need full control over the raw event payload:

\Swiftyper\Catcher::get()->sendEvent([
    'title'   => 'Custom event title',
    'context' => [
        'orderId' => 1234,
    ],
]);

Filtering sensitive information

Emperror already filter a few obvious things for you before an event ever leaves your server:

  • Sensitive request headers - Authorization, Cookie, Proxy-Authorization, X-Api-Key, X-Auth-Token, X-Csrf-Token - are replaced with [Filtered].
  • Function/method arguments whose name looks like a secret (password, token, secret, apiKey, auth, ...) are replaced with [Filtered] in stack traces.

For anything else - user emails, custom context fields, or your own payloads - use the beforeSend hook. Use the EventPayload getters/setters to inspect or clear any property before it's sent:

\Swiftyper\Emperror::setup([
    // ...
    'beforeSend' => function (\Swiftyper\EventPayload $eventPayload) {
        $user = $eventPayload->getUser();
        
        if (!empty($user['email'])){
            unset($user['email']);
        
            $eventPayload->setUser($user);
        }

        return $eventPayload;
    }
]);

๐Ÿงช Testing

$ composer tests

๐Ÿค Contributing

Please see CONTRIBUTING for details.

๐Ÿ“œ License

This project is licensed under the MIT License. See the LICENSE file for details.