Laravel error catcher for Hawk.so.
-
Register an account, create a project, and get an Integration Token.
-
Install the SDK via Composer:
composer require codex-team/hawk.laravel
- PHP 7.2+
- Laravel 11.x+
- 🦅 Automatic error catching
- 💎 Manual exception and message sending
- 🙂 Attaching user information
- 📦 Attaching additional context
- 🛡️ Sensitive data filtering
- 🌟 BeforeSend hook for event preprocessing
- 🗂️ Breadcrumbs collection (routes, queries, jobs, logs)
- ⚡ Laravel 11+ support
Update your bootstrap/app.php
:
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
HawkBundle\Integration::handles($exceptions);
})
->create();
Add the Hawk
service provider to your config/app.php
or bootstrap/providers.php
:
'providers' => [
// Other service providers...
HawkBundle\ErrorLoggerServiceProvider::class,
],
Run:
php artisan hawkbundle:publish
This will create config/hawk.php
.
Then add your token in .env
:
HAWK_TOKEN=<your_integration_token>
app(\HawkBundle\Catcher::class)->setUser([
'name' => 'John Doe',
'photo' => 'https://example.com/avatar.png',
]);
app(\HawkBundle\Catcher::class)->setContext([
'page' => 'checkout',
'cart_id' => 123,
]);
Inject \HawkBundle\Catcher
and call sendException
:
use HawkBundle\Catcher;
class TestController extends Controller
{
private Catcher $catcher;
public function __construct(Catcher $catcher)
{
$this->catcher = $catcher;
}
public function test()
{
try {
// Code that may fail
} catch (\Exception $e) {
$this->catcher->sendException($e);
}
}
}
app(\HawkBundle\Catcher::class)->sendMessage(
'Checkout started',
[
'cart_id' => 123,
'step' => 'payment',
]
);
If you want to modify or filter errors before they are sent to Hawk,
implement the BeforeSendServiceInterface
.
Example:
<?php
namespace App\Hawk;
use Hawk\EventPayload;
use HawkBundle\Services\BeforeSendServiceInterface;
class BeforeSendService implements BeforeSendServiceInterface
{
public function __invoke(EventPayload $eventPayload): ?EventPayload
{
$user = $eventPayload->getUser();
// Remove sensitive data
if (!empty($user['email'])) {
unset($user['email']);
$eventPayload->setUser($user);
}
// Skip sending in specific cases
if ($eventPayload->getContext()['skip_sending'] ?? false) {
return null;
}
return $eventPayload;
}
}
Register it in config/hawk.php
:
return [
'integration_token' => env('HAWK_TOKEN'),
'before_send_service' => \App\Hawk\BeforeSendService::class,
];
- Found a bug? Open an issue
- Want to improve the package? Pull requests are welcome!
- Repository: github.com/codex-team/hawk.laravel
- Composer Package: packagist.org/packages/codex-team/hawk.laravel
- CodeX Team: codex.so