PHPackages                             antarctica/laravel-json-exception-formatter - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. antarctica/laravel-json-exception-formatter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

antarctica/laravel-json-exception-formatter
===========================================

A custom interface for the Laravel JSON Exception Formatter package.

v0.1.4(11y ago)2641MITPHPPHP &gt;=5.4.0

Since Dec 12Pushed 11y ago2 watchersCompare

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

READMEChangelogDependencies (1)Versions (6)Used By (0)

Laravel JSON Exception Formatter
================================

[](#laravel-json-exception-formatter)

A custom interface for the Laravel [JSON Exception Formatter](https://github.com/Radweb/JSON-Exception-Formatter) package.

This package is designed to work with exceptions that extend the [antarctica/laravel-base-exceptions](https://packagist.org/packages/antarctica/laravel-base-exceptions) package, but does not require this.

Installing
----------

[](#installing)

Require this package in your `composer.json` file:

```
{
	"require": {
		"antarctica/laravel-json-exception-formatter": "dev-develop"
	}
}
```

Run `composer update`.

Register the service provider in `app/config/app.php`:

```
'providers' => array(

	'Antarctica\JsonExceptionFormatter\JsonExceptionFormatterServiceProvider',

),
```

Note: this package automatically requires and registers the [JSON Exception Formatter](https://github.com/Radweb/JSON-Exception-Formatter) package behind the scenes.

Usage
-----

[](#usage)

Registering the service provider is enough to automatically call this package. The underlying [JSON Exception Formatter](https://github.com/Radweb/JSON-Exception-Formatter) is triggered whenever a request that requests a JSON response (i.e. `accept: application/json`) and an exception is thrown.

This package is a [Custom Formatter](https://github.com/Radweb/JSON-Exception-Formatter#custom-formatters) of this underlying package.

It provides an alternative representation for exceptions as errors for both debug and non-debug environments.

The main difference in our custom implementation is the inclusion of the custom properties available to exceptions that extend the [HttpException](https://github.com/antarctica/laravel-base-exceptions#httpexception) exception from the [antarctica/laravel-base-exceptions](https://packagist.org/packages/antarctica/laravel-base-exceptions) package.

Exceptions extending other exceptions will be rendered without this extra information, but do not remove any information (i.e. this package becomes transparent).

In addition to extra error information, debug environments will include the PHP stack trace in responses to aid to diagnostics.

### Example usage

[](#example-usage)

Exception on which responses are based upon:

```
