PHPackages                             rawnoq/laravel-exceptions - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. rawnoq/laravel-exceptions

ActiveLibrary[HTTP &amp; Networking](/categories/http)

rawnoq/laravel-exceptions
=========================

A professional Laravel package for centralized API exception handling with unified response structure

1.0.0(5mo ago)051MITPHPPHP ^8.2

Since Nov 26Pushed 5mo agoCompare

[ Source](https://github.com/rawnoq/laravel-exceptions)[ Packagist](https://packagist.org/packages/rawnoq/laravel-exceptions)[ Docs](https://github.com/rawnoq/laravel-exceptions)[ RSS](/packages/rawnoq-laravel-exceptions/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Rawnod Laravel Exceptions
=========================

[](#rawnod-laravel-exceptions)

[![Latest Version](https://camo.githubusercontent.com/bf88a1727a79026b8157232ec7d9edc166d7067ce634f7af0a4c71bce4566416/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f7261776e6f712f6c61726176656c2d657863657074696f6e733f7374796c653d666c61742d737175617265)](https://github.com/rawnoq/laravel-exceptions/releases)[![License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/9968a813e276990957d97684b89e22c8e87df0de6d9a92ba8484a68273a93fe3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e322d626c75652e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![Laravel Version](https://camo.githubusercontent.com/0922242fd9e6faba90e4c0d4fce319b304abe968fed951f7a3bd26d28c96e158/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d25354531312e3025374325354531322e302d7265642e7376673f7374796c653d666c61742d737175617265)](https://laravel.com)

A professional Laravel package for centralized API exception handling with unified response structure, status codes, and messages.

Features
--------

[](#features)

- 🎯 **Centralized Exception Handling**: Single point of control for all API exceptions
- 📦 **Unified Response Structure**: Consistent JSON responses across all exceptions
- 🔒 **Security First**: Hides sensitive information in production
- 📝 **Comprehensive Logging**: Automatic logging of unhandled exceptions
- 🔧 **Highly Customizable**: Easy to extend and customize
- 🚀 **Laravel 11+ Ready**: Built for Laravel 11 and 12

Installation
------------

[](#installation)

### Via Composer

[](#via-composer)

```
composer require rawnod/laravel-exceptions
```

### Manual Installation

[](#manual-installation)

If you're installing manually, add the package to your `composer.json`:

```
{
    "repositories": [
        {
            "type": "path",
            "url": "./packages/rawnod/laravel-exceptions"
        }
    ],
    "require": {
        "rawnod/laravel-exceptions": "*"
    }
}
```

Then run:

```
composer install
```

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=exceptions-config
```

This will create `config/exceptions.php` where you can customize exception handling behavior.

Setup
-----

[](#setup)

### Automatic Registration (Recommended)

[](#automatic-registration-recommended)

By default, the package automatically registers the exception handler. No manual configuration is required!

The handler will automatically work for all routes matching the `api_pattern` (default: `api/*`).

To disable automatic registration, set in your `.env`:

```
EXCEPTIONS_AUTO_REGISTER=false
```

### Manual Registration (Optional)

[](#manual-registration-optional)

If you disabled automatic registration, you can manually register the exception handler in your `bootstrap/app.php`:

```
use Rawnod\Exceptions\ExceptionRenderer;
use Illuminate\Foundation\Configuration\Exceptions;

return Application::configure(basePath: dirname(__DIR__))
    // ... other configuration
    ->withExceptions(function (Exceptions $exceptions): void {
        $exceptions->render(function (\Throwable $e, $request) {
            if ($request->is('api/*')) {
                return app(ExceptionRenderer::class)->render($e);
            }
        });
    })->create();
```

Supported Exceptions
--------------------

[](#supported-exceptions)

The package handles the following exception types:

- `HttpResponseException` - Custom HTTP responses
- `ModelNotFoundException` - Eloquent model not found
- `NotFoundHttpException` - Route not found
- `MethodNotAllowedHttpException` - HTTP method not allowed
- `ValidationException` - Form validation errors
- `AuthenticationException` - Unauthenticated requests
- `AuthorizationException` - Unauthorized access
- `InvalidFilterQuery` - Spatie QueryBuilder filter errors
- `InvalidIncludeQuery` - Spatie QueryBuilder include errors
- `InvalidSortQuery` - Spatie QueryBuilder sort errors
- `InvalidFieldQuery` - Spatie QueryBuilder field errors
- `HttpExceptionInterface` - All other HTTP exceptions
- Generic exceptions - Fallback for unhandled exceptions

Usage
-----

[](#usage)

Once installed and configured, the exception handler will automatically catch and format all exceptions for API routes.

### Language Files

[](#language-files)

The package includes built-in translations in English and Arabic. Translations are automatically loaded from the package.

#### Available Translation Keys

[](#available-translation-keys)

- `exceptions::exceptions.model_not_found` - Model not found message
- `exceptions::exceptions.resource_not_found` - Resource not found message
- `exceptions::exceptions.method_not_allowed` - HTTP method not allowed
- `exceptions::exceptions.validation_failed` - Validation failed message
- `exceptions::exceptions.unauthenticated` - Authentication required
- `exceptions::exceptions.unauthorized` - Authorization failed
- `exceptions::exceptions.server_error` - Server error message
- `exceptions::exceptions.http_exception` - Generic HTTP exception
- `exceptions::exceptions.bad_request` - Bad request message

#### Customizing Translations

[](#customizing-translations)

You can publish and customize the language files:

```
php artisan vendor:publish --tag=exceptions-lang
```

This will copy the language files to `lang/vendor/exceptions/` where you can customize them.

Alternatively, you can override translations in your application's language files by creating files at:

- `lang/en/vendor/exceptions/exceptions.php`
- `lang/ar/vendor/exceptions/exceptions.php`

### Response Structure

[](#response-structure)

All exceptions return a consistent JSON structure using the `rawnoq/laravel-api-response` package format:

```
{
    "success": false,
    "message": "Error message",
    "data": null,
    "errors": {}
}
```

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11.0+ or 12.0+
- `rawnoq/laravel-api-response` package

Optional Dependencies
---------------------

[](#optional-dependencies)

- `spatie/laravel-query-builder` - For query builder exception handling

License
-------

[](#license)

MIT

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Support
-------

[](#support)

For issues and questions, please open an issue on [GitHub](https://github.com/rawnoq/laravel-exceptions/issues).

Links
-----

[](#links)

- [GitHub Repository](https://github.com/rawnoq/laravel-exceptions)
- [Issue Tracker](https://github.com/rawnoq/laravel-exceptions/issues)

###  Health Score

37

—

LowBetter than 82% of packages

Maintenance75

Regular maintenance activity

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

164d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fef8f5b623783c112ea9b179c610918e020a18fe0e921a48dc45c351cb7b5115?d=identicon)[HassanHassanKerdash](/maintainers/HassanHassanKerdash)

---

Top Contributors

[![HassanHassanKerdash](https://avatars.githubusercontent.com/u/220541638?v=4)](https://github.com/HassanHassanKerdash "HassanHassanKerdash (1 commits)")[![HassanKerdashMoltaqa](https://avatars.githubusercontent.com/u/235504083?v=4)](https://github.com/HassanKerdashMoltaqa "HassanKerdashMoltaqa (1 commits)")

---

Tags

jsonapilaravelrestexceptionserror handling

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rawnoq-laravel-exceptions/health.svg)

```
[![Health](https://phpackages.com/badges/rawnoq-laravel-exceptions/health.svg)](https://phpackages.com/packages/rawnoq-laravel-exceptions)
```

###  Alternatives

[chrisbjr/api-guard

A simple way of authenticating your APIs with API keys using Laravel

698375.6k5](/packages/chrisbjr-api-guard)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
