PHPackages                             jccoca/laravel-api-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. jccoca/laravel-api-exceptions

ActiveLibrary

jccoca/laravel-api-exceptions
=============================

A clean and highly customizable REST API Exception Handler for Laravel.

v1.0.1(1mo ago)011MITPHPPHP ^8.4

Since Jul 14Pushed 1mo agoCompare

[ Source](https://github.com/JCCoca/laravel-api-exceptions)[ Packagist](https://packagist.org/packages/jccoca/laravel-api-exceptions)[ RSS](/packages/jccoca-laravel-api-exceptions/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Laravel API Exceptions
======================

[](#laravel-api-exceptions)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8d8c19036d4458a6cae9f7be8786f2e9e1ce64b13d2ed217fb037d77d5e562f7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a63636f63612f6c61726176656c2d6170692d657863657074696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jccoca/laravel-api-exceptions)[![Total Downloads](https://camo.githubusercontent.com/52a8ac3a6caf01edaf783ac4b633b6bfb8787c82e4560bbaf34e8467578e3ef3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a63636f63612f6c61726176656c2d6170692d657863657074696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jccoca/laravel-api-exceptions)[![License](https://camo.githubusercontent.com/16cabcf6d90f10e95576f6b0a2aab34f8cb766895159da5b304038f50365ab85/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4a43436f63612f6c61726176656c2d6170692d657863657074696f6e732e7376673f7374796c653d666c61742d737175617265)](LICENSE)

🇧🇷 **[Para a versão em Português, clique aqui](./README.pt-BR.md)**

A lightweight and elegant package to standardize and customize HTTP error and exception responses in **Laravel 11, 12, and 13+** REST APIs.

✨ Features
----------

[](#-features)

- ⚡ **Auto-Format Errors:** Catch common API errors (401, 403, 404, 405, 422, 500) and return a consistent JSON payload structure.
- ⚙️ **Highly Customizable:** Easily change both the error title (`error`) and the explanation (`message`) for any exception using a simple config file.
- 🛠️ **Force JSON Middleware:** Automatically forces all `/api` prefixed routes to return `application/json` transparently.
- 🐛 **Smart Debugging:** Shows file, line, and a clean, simplified stack trace when `APP_DEBUG=true`.
- 🛡️ **Production-Safe:** Automatically hides database details and PHP error messages when the application is in production mode.

---

🚀 Installation
--------------

[](#-installation)

You can install the package via Composer:

```
composer require jccoca/laravel-api-exceptions
```

---

🛠️ Configuration
----------------

[](#️-configuration)

### 1. Bind the Handler in Laravel

[](#1-bind-the-handler-in-laravel)

Open your Laravel application's bootstrap/app.php file and call the handler inside the withExceptions block:

```
