encodia/laravel-something-wrong

A simple package for Laravel to notify handled errors, exceptions and more

0.2.0 2023-02-19 17:35 UTC

README

68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f737570706f72742d756b7261696e652e7376673f743d31

Something wrong

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status

Total Downloads

A simple package for Laravel to notify handled errors, exceptions and more.

Note: this package is still under development and currently its features are very limited.

Installation

You can install the package via composer:

composer require encodia/laravel-something-wrong

You can publish the config file with:

php artisan vendor:publish --tag="laravel-something-wrong-config"

Usage

Note: the current version only supports Bugsnag.

This means that anything you notify will use Bugsnag under the hood to send a notification.

Where

Typically, you will inject Encodia\SomethingWrong in your service class constructor:

use \Encodia\SomethingWrong;

class MyService {
    private SomethingWrong $somethingWrong;

    public function __construct(SomethingWrong $somethingWrong)
    {        
        $this->somethingWrong = $somethingWrong;
    }
    
    public function doSomething(): void
    {
        // ...
        $this->somethingWrong
            ->exception(
                new \Exception("This wasn't supposed to happen, so let's notify it!")
        );
        
        // ...        
    }
}

    

If you prefer, you can use its facade:

use \Encodia\SomethingWrong\Facades\SomethingWrong;

// ...
SomethingWrong::exception(
    new \Exception("This wasn't supposed to happen, so let's notify it!")
);

How

You can notify a simple exception, without any further details:

SomethingWrong::exception(
    new \Exception("Something wrong happened!")
);

If you need to add any details, just pass an array as second argument:

SomethingWrong::exception(
    new \Exception("Something wrong happened!"),
    [
        'foo' => 'bar',
        'path' => 'a/b/c',
        'user' => auth()->user,
    ],
);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.