PHPackages                             radweb/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. radweb/json-exception-formatter

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

radweb/json-exception-formatter
===============================

JSON for your Exceptions

0.2.0(11y ago)92.1k4[1 issues](https://github.com/Radweb/JSON-Exception-Formatter/issues)1MITPHPPHP &gt;=5.3.0

Since Feb 13Pushed 11y ago6 watchersCompare

[ Source](https://github.com/Radweb/JSON-Exception-Formatter)[ Packagist](https://packagist.org/packages/radweb/json-exception-formatter)[ RSS](/packages/radweb-json-exception-formatter/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (3)Versions (3)Used By (1)

[![](https://camo.githubusercontent.com/b81f949074de87a2e7cbe58ac0e7293e6c869eff3bd2213f91389f414fe07364/687474703a2f2f692e696d6775722e636f6d2f51736c6872357a2e706e67)](http://radweb.co.uk)

[![Build Status](https://camo.githubusercontent.com/9505a278836afb308aca21f0906238721a1c3bb31650203b0d87def337d7bc57/68747470733a2f2f7472617669732d63692e6f72672f5261647765622f4a534f4e2d457863657074696f6e2d466f726d61747465722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/Radweb/JSON-Exception-Formatter) [![Latest Stable Version](https://camo.githubusercontent.com/317da73559fbd36c6132fd1589f58742df9a3997d7f7548f580e9af82aecf15b/68747470733a2f2f706f7365722e707567782e6f72672f7261647765622f6a736f6e2d657863657074696f6e2d666f726d61747465722f762f737461626c652e706e67)](https://packagist.org/packages/radweb/json-exception-formatter) [![License](https://camo.githubusercontent.com/423c2be9ee97a9ff6ce2c05f333aa37d0be26fbd6126e222443c036b35654d92/68747470733a2f2f706f7365722e707567782e6f72672f7261647765622f6a736f6e2d657863657074696f6e2d666f726d61747465722f6c6963656e73652e706e67)](https://packagist.org/packages/radweb/json-exception-formatter)

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

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

A small Laravel package to format &amp; output exceptions in JSON format when required.

By default in Laravel, throwing an Exception in debug mode will display a nice JSON response when required (eg. an AJAX response, or an `Accept: application/javascript` header).

However once you're not in debug mode (ie. a production environment), a whole HTML response is displayed instead.

With this package, when you're not in debug mode, exceptions will be output as JSON (only without debug information like the file name &amp; line number).

**NOTE** This does NOT affect HTML requests. Only AJAX/JSON requests are altered.

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

[](#installation)

Add `radweb/json-exception-formatter` to your `composer.json` file.

```
{
    "require": {
        "radweb/json-exception-formatter": "dev-master"
    }
}
```

In `app/config/app.php`, add the Service Provider to the `providers` array:

```
array(
    'providers' => array(
        // ...
        'Radweb\JsonExceptionFormatter\JsonExceptionFormatterServiceProvider',
    )
)
```

Custom Formatters
-----------------

[](#custom-formatters)

You can override the default JSON exception formatter to use a different format, or provide more detail in the output.

To override, implement the `Radweb\JsonExceptionFormatter\FormatterInterface` interface, and bind with the IoC container. This requires you to implement two methods: `formatDebug()` and `formatPlain()`.

Example implementation:

```
