Skip to content

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages