Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Custom Exception Handler Laravel Package

bytestechnolabs/custom-exception-handler

Laravel package for configurable exception handling: map exception classes to custom messages, HTTP status codes, and extra response data via config. Includes helper to add custom data dynamically during catch blocks for consistent API error responses.

View on GitHub
Deep Wiki
Context7

Certainly, here's a sample README file for your Laravel package, the Custom Exception Handler:

# Custom Exception Handler for Laravel

The **Custom Exception Handler for Laravel** is a package designed to provide custom exception handling within your Laravel application. It allows you to specify how different types of exceptions should be handled, set custom HTTP response codes, define error messages, and even provide custom data to be included in the response.

## Installation

You can easily install the package via Composer:

```shell
composer require bytestechnolabs/custom-exception-handler

Configuration

After installation, you can configure the Custom Exception Handler by publishing the configuration file. This file enables you to define which exceptions to handle and how they should be handled.

To publish the configuration file, run the following command:

php artisan vendor:publish --provider="BytesTechnolabs\CustomExceptionHandler\CustomExceptionHandlerServiceProvider"

Usage

Custom Exception Handling

The Custom Exception Handler allows you to handle specific exceptions differently. You can customize:

  • Error messages
  • HTTP response codes
  • Custom data to include in the response

Here is an example of how to handle a CustomException:

  1. Add the exception class name to the configuration:
'exceptions' => [
    // ... Other exception classes
    'CustomException',
],
  1. Set the desired error message, HTTP status code, and custom data for the CustomException:
'exceptions_messages' => [
    // ... Other exception messages
    'CustomException' => 'A custom exception occurred.',
],

'exceptions_status_codes' => [
    // ... Other exception status codes
    'CustomException' => 400,
],

'custom_data' => [
    'CustomException' => [
        'custom_key' => 'custom_data_key',
        'data' => ['custom' => 'data'],
    ],
],

Dynamic Custom Data

You can also add custom data dynamically during exception handling by using the CustomDataHelper class provided by the package:

use BytesTechnolabs\CustomExceptionHandler\CustomDataHelper;

try {
    // Code that may throw an exception
} catch (\Exception $exception) {
    // Add custom data to the response
    CustomDataHelper::addCustomDataToConfig($exception, ['custom' => 'data'], 'custom_data_key');

    // Rethrow the Exception
    throw $exception;
}

Support and Issues

If you encounter any issues or have questions about the Custom Exception Handler for Laravel, please report them on GitHub.

License

This package is open-source software licensed under the MIT License.

Author

Version

The current version of the package is 1.6.0.

Changelog

For release notes and changes, please refer to the GitHub releases.

We hope you find the Custom Exception Handler for Laravel useful. If you have any suggestions or improvements for this package, feel free to contribute to the project on GitHub.


You can copy and paste this README into your project's README.md file and make any necessary adjustments to reflect your package's specifics.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky