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

00PHP

Since Jun 26Pushed todayCompare

[ 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 today

READMEChangelogDependenciesVersions (1)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

20

—

LowBetter than 13% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### 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

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25025.5M80](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.2M6.5k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k20.0k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87930.4k113](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.3M84](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69122.6k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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