PHPackages                             robrogers3/laravel-jsonaware-exception-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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. robrogers3/laravel-jsonaware-exception-handler

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

robrogers3/laravel-jsonaware-exception-handler
==============================================

Laravel Json Aware Exception Handler

1.1.8(7y ago)613[1 issues](https://github.com/robrogers3/laravel-jsonaware-exception-handler/issues)MITPHPPHP &gt;=5.6.0

Since Jul 28Pushed 7y ago1 watchersCompare

[ Source](https://github.com/robrogers3/laravel-jsonaware-exception-handler)[ Packagist](https://packagist.org/packages/robrogers3/laravel-jsonaware-exception-handler)[ RSS](/packages/robrogers3-laravel-jsonaware-exception-handler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (10)Versions (10)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0447ee07d15f5ce36a62ba258e614e721a5c98ddbb30932265edce7c35a2a0c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f62726f67657273332f6c61726176656c2d6a736f6e61776172652d657863657074696f6e2d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/robrogers3/laravel-jsonaware-exception-handler)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/a02468acda7ab8d05a53b66c58dc36443a29711b48de70c228b5d66b954e85ef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f62726f67657273332f6c61726176656c2d6a736f6e61776172652d657863657074696f6e2d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/robrogers3/laravel-jsonaware-exception-handler)[![Build Status](https://camo.githubusercontent.com/e8ec71732aacb908c14a53ec36e4a692d1354c748d6fdfe698724db2bab46816/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f726f62726f67657273332f6c61726176656c2d6a736f6e61776172652d657863657074696f6e2d68616e646c65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/robrogers3/laravel-jsonaware-exception-handler)

Laravel Json Aware Exception Handler
====================================

[](#laravel-json-aware-exception-handler)

Every one likes cool error message pages. Github has an awesome 404.

And it's very easy to create your own custom error pages for html responses.

But doing this for Ajax and Json responses meant either doing something generic or figuring out your own solution. Often something like returning an error message like 'Sorry we cant handle your request'. Nothing informative.

This package solves this problem.

Once it's installed. Tune your error messages for over a dozen possible error codes. You can even add more. Just create a ZizzZazzException assign a status code to it, and a custom message. Done!

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

[](#installation)

Install Laravel Json Aware Exception Handler with Composer.

```
$ composer require robrogers3/laravel-json-aware-exception-handler
```

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

[](#configuration)

```
RobRogers3\LaravelExceptionHandler\ServiceProvider::class,
```

### Using it:

[](#using-it)

Option 1: Update your .env file by adding this line:

USE\_JSON\_EXCEPTION\_HANDLER=true

This will use the JsonHandler for json requests and the Laravel Exception Handler for regular requests.

Note: it will completely ignore your app's Exception Handler. This means you can't override anything in this class.

Option 2: Update your App Handler class to extend the JsonAwareExceptionHandler

You do not have to update your .env file.

The benefit of this is you can overide how the JsonAwareExceptionHandler

To do this you need to change your `App\Exceptions\Handler` class to extend `RobRogers3\LaravelExceptionHandler\JsonAwareExceptionHandler` rather than extending `Illuminate\Foundation\Exceptions\Handler`. Like so:

```
