PHPackages                             devgh/api-error-handler - 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. devgh/api-error-handler

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

devgh/api-error-handler
=======================

Laravel API Error Handler

v1.2.0(1mo ago)06MITPHPPHP &gt;=8.1

Since Jun 26Pushed 1mo agoCompare

[ Source](https://github.com/Gha-zy001/api-error-handler)[ Packagist](https://packagist.org/packages/devgh/api-error-handler)[ RSS](/packages/devgh-api-error-handler/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

API Error Handler
=================

[](#api-error-handler)

A Laravel package that provides centralized JSON error handling for API applications.

Instead of repeating exception handling logic in every project, this package automatically converts Laravel exceptions into consistent JSON responses and optionally logs them.

**Compatibility**

- This package currently supports **Laravel 10 and earlier**.
- Support for **Laravel 11+** will be available in a future major release.

Features
--------

[](#features)

- Centralized API exception handling
- Standardized JSON error responses
- Automatic exception logging
- Configurable response keys
- Configurable log channel
- Debug mode support
- Publishable configuration
- Supports common Laravel exceptions

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

[](#supported-exceptions)

- ValidationException
- AuthenticationException
- AuthorizationException
- ModelNotFoundException
- NotFoundHttpException
- MethodNotAllowedHttpException
- TooManyRequestsHttpException
- QueryException
- HttpException
- Generic Exception

---

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

[](#installation)

Install the package via Composer.

```
composer require devgh/api-error-handler
```

Publish the configuration file.

```
php artisan vendor:publish --tag=error-handler-config
```

---

Usage
-----

[](#usage)

No additional setup is required.

The package automatically intercepts API exceptions for requests that:

- use the `api/*` route prefix
- or expect JSON responses.

Example:

```
Route::get('/users/{id}', function ($id) {
    return User::findOrFail($id);
});
```

Request:

```
GET /api/users/999

```

Response:

```
{
    "success": false,
    "message": "User not found.",
    "code": 404
}
```

---

Validation Errors
-----------------

[](#validation-errors)

```
{
    "success": false,
    "message": "The given data was invalid.",
    "code": 422,
    "errors": {
        "email": [
            "The email field is required."
        ]
    }
}
```

---

Debug Mode
----------

[](#debug-mode)

When `APP_DEBUG=true`, responses include debugging information.

```
{
    "success": false,
    "message": "...",
    "code": 500,
    "debug": {
        "exception": "...",
        "file": "...",
        "line": 45,
        "trace": [...]
    }
}
```

---

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

[](#configuration)

```
return [

    'debug' => env('APP_DEBUG', false),

    'log_errors' => true,

    'log_channel' => env('LOG_CHANNEL', 'stack'),

    'dont_report' => [

    ],

    'response_keys' => [
        'success' => 'success',
        'message' => 'message',
        'errors' => 'errors',
        'code' => 'code',
        'debug' => 'debug',
    ],

];
```

---

Logging
-------

[](#logging)

Handled exceptions are automatically logged using Laravel's logging system.

You may configure:

- log channel
- exceptions that should not be reported
- disable logging completely

---

Example Response
----------------

[](#example-response)

```
{
    "success": false,
    "message": "Unauthenticated.",
    "code": 401
}
```

---

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance91

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Every ~1 days

Total

3

Last Release

43d ago

PHP version history (2 changes)v1.0.0PHP ^8.1

v1.1.0PHP &gt;=8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/129204847?v=4)[Ahmed Ebrahim](/maintainers/Gha-zy001)[@Gha-zy001](https://github.com/Gha-zy001)

---

Top Contributors

[![Gha-zy001](https://avatars.githubusercontent.com/u/129204847?v=4)](https://github.com/Gha-zy001 "Gha-zy001 (5 commits)")

### Embed Badge

![Health badge](/badges/devgh-api-error-handler/health.svg)

```
[![Health](https://phpackages.com/badges/devgh-api-error-handler/health.svg)](https://phpackages.com/packages/devgh-api-error-handler)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k31.8M158](/packages/laravel-cashier)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

79227.1M210](/packages/laravel-mcp)[illuminate/auth

The Illuminate Auth package.

9328.5M1.3k](/packages/illuminate-auth)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

818355.4k3](/packages/defstudio-telegraph)

PHPackages © 2026

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