PHP code example of adaptit-darshan / exception-notifier
1. Go to this page and download the library: Download adaptit-darshan/exception-notifier library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adaptit-darshan / exception-notifier example snippets
use Damku999\ExceptionNotifier\JsonExceptionHandler;
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',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
//
})
->withExceptions(function (Exceptions $exceptions) {
$exceptions->render(function (Throwable $e) {
return app(JsonExceptionHandler::class)->handle($e);
});
})->create();
// Any uncaught exception will trigger an email notification
throw new \Exception('Something went wrong!');
// Validation exceptions are ignored by default (configurable)
throw ValidationException::withMessages(['email' => 'Invalid email']);
// Database exceptions are marked as critical (always sent)
DB::table('non_existent')->get(); // Triggers critical email
use Damku999\ExceptionNotifier\Facades\ExceptionNotifier;
try {
// Your code
} catch (\Throwable $e) {
ExceptionNotifier::notify($e);
// Continue with your error handling
}
use Damku999\ExceptionNotifier\Facades\ExceptionNotifier;
// Check if rate limit exceeded for specific exception
$signature = ExceptionNotifier::generateSignature($exception);
$exceeded = ExceptionNotifier::isRateLimitExceeded($signature);
// Get current count for signature
$count = ExceptionNotifier::getRateLimitCount($signature);
// Get all rate limit statuses
$statuses = ExceptionNotifier::getRateLimitStatus();
// In your AppServiceProvider or config
config([
'exception_notifier.branding' => [
'email_logo' => 'images/logo.png',
'primary_color' => '#007bff',
'text_color' => '#333333',
'footer_text' => 'Your Company Name',
'support_email' => '[email protected]',
],
]);