PHPackages                             lalu/jer - 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. [API Development](/categories/api)
4. /
5. lalu/jer

ActiveLibrary[API Development](/categories/api)

lalu/jer
========

A laravel/lumen package for structing API exception response in JSON followed http://jsonapi.org/

v1.0.1(10y ago)153MITPHP ~5.5|~7.0

Since May 31Compare

[ Source](https://github.com/thanh-taro/lalu-jer)[ Packagist](https://packagist.org/packages/lalu/jer)[ RSS](/packages/lalu-jer/feed)WikiDiscussions Synced yesterday

READMEChangelog (2)Dependencies (3)Versions (5)Used By (0)

Json Exception Response
=======================

[](#json-exception-response)

[![Latest Stable Version](https://camo.githubusercontent.com/1772d4e46b7bac8802b3f7f527ce3d0500a08eca639d6099b52cc7b69956ffea/68747470733a2f2f706f7365722e707567782e6f72672f6c616c752f6a65722f762f737461626c65)](https://packagist.org/packages/lalu/jer)[![Build Status](https://camo.githubusercontent.com/027e7801ec1dfc25fb9283f734fff027e0eebf36996083f0d8f2915fcb626a12/68747470733a2f2f7472617669732d63692e6f72672f7468616e682d7461726f2f6c616c752d6a65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/thanh-taro/lalu-jer)[![Coverage Status](https://camo.githubusercontent.com/66162d05cd9b1a608d6726a5caf79f6516d1a5b8d61fc152fd33df6fc970b5c9/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7468616e682d7461726f2f6c616c752d6a65722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/thanh-taro/lalu-jer?branch=master)[![Total Downloads](https://camo.githubusercontent.com/a6233dba24ce312ce5429516bf16461b43dcd468eeba2bae39ca70b3608c67a0/68747470733a2f2f706f7365722e707567782e6f72672f6c616c752f6a65722f646f776e6c6f616473)](https://packagist.org/packages/lalu/jer) [![License](https://camo.githubusercontent.com/e88854db4d12d1040565c069f1e43a5438462000b2d721f8d1d73f4cd632ff01/68747470733a2f2f706f7365722e707567782e6f72672f6c616c752f6a65722f6c6963656e7365)](https://packagist.org/packages/lalu/jer)

A Laravel/Lumen package for structing API exception response in JSON followed .

Install
-------

[](#install)

Via Composer

```
$ composer require lalu/jer
```

### Laravel

[](#laravel)

Once this has finished, you will need to add the service provider to the providers array in your `config/app.php` as follows:

```
'providers' => [
    // ...
    LaLu\JER\JERServiceProvider::class,
]
```

If you want to use alias, also in the app.php config file, under the aliases array, you may want to add facades as follows:

```
'aliases' => [
    // ...
    'JER' => LaLu\JER\Facades\JERFacade::class
]
```

Then, publish the localization by running:

```
php artisan vendor:publish
```

### Lumen

[](#lumen)

Open `bootstrap/app.php` and add this line:

```
$app->register(LaLu\JER\JERServiceProvider::class);
```

If you want to use alias, also in your bootstrap/app.php, make sure you have uncommented

```
$app->withFacades();
```

Then, add this line:

```
class_alias(LaLu\JER\Facades\JERFacade::class, 'JER');
```

For localization, you have to create `messages.php` under `resources/lang/vendor/lalu-jer/en` (default is en - English). All built-in message ids are in [here](https://github.com/thanh-taro/lalu-jer/blob/master/src/resources/lang/en/messages.php)

Usage
-----

[](#usage)

In the `app\Exceptions\Handler.php`, let the class extends `LaLu\JER\ExceptionHandler`.

```
use LaLu\JER\ExceptionHandler;

class Handler extends ExceptionHandler
{
    // ...
}
```

Then all of Exceptions will handle by this package.

You can also use `abort` or `throw new \Exception\You\Want()` to raise and response exception.

Advanced
--------

[](#advanced)

Add `meta` to response json? It's not a big deal.

```
use LaLu\JER\ExceptionHandler;

class Handler extends ExceptionHandler
{
    public $meta = [
        'meta_field_1' => 'meta_value_1',
        // ...
    ];

    // ...
}
```

Or

```
use LaLu\JER\ExceptionHandler;

class Handler extends ExceptionHandler
{
    public function beforeRender($request, Exception $exception)
    {
        $this->meta = [
            'meta_field_1' => 'meta_value_1',
            // ...
        ];
    }

    // ...
}
```

With `beforeRender` which will be raised before the `render` method, you can do more logics to set meta, headers and so on.

If you want to custom the response of some Exception classes, just override the `getExceptionError`.

```
use LaLu\JER\ExceptionHandler;
use LaLu\JER\Error;

class Handler extends ExceptionHandler
{
    // ...

    /**
     * Get exception jsonapi data.
     *
     * @param \Exception $exception
     *
     * @return array
     */
    protected function getExceptionError(Exception $exception)
    {
        if ($exception instanceof \Exception\You\Want) {
            // status must be an integer and is a HTTP error status code
            $status = 400;
            // headers must be an array of key value
            $headers = [];
            $content = [
                'title' => 'Your exception custom title',
                'detail' => 'Your exception custom detail',
            ];
            // error can be an instance/array items of \LaLu\JER\Error or array of error array
            $error = new Error(['version' => $this->jsonapiVersion], $content);
            $error->status = '400';
            // ...
            return [$status, $error, $headers];
        } elseif ($exception instanceof \Other\Exception) {
            return [400, [['title' => 'Your request is bad request']], []];
        } else {
            return parent::getExceptionError($exception);
        }
    }
}
```

If you want to custom error json response, feel free to use this function:

```
$option = [
    'version' => '1.0', // JSONAPI specification version
    'status' => 400, // HTTP status code
    'headers' => ['My-Custom-Header' => 'Value'], // Response headers,
    'exception' => new \Exception(), // Exception
];
$attributes = [
    'meta' => [
        'apiVersion' => '1.0.0',
        'author' => 'thanh-taro',
    ],
    'errors' => new Error(['version' => '1.0'], ['title' => 'My custom error', 'detail' => 'This is an error response']), // Error content
];
$response = \JER::getResponse($option, $attributes);
```

Note that `JER` is an alias, if you didn't config for alias, you may use

```
(new \LaLu\JER\JsonExceptionResponse())->getResponse($option, $attributes);
```

License
-------

[](#license)

The MIT License (MIT).

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity61

Established project with proven stability

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.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

3681d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d3874d166020d57e674e421e87ff84f03cd8191feae7801352debf6f35b3cf7f?d=identicon)[adamnguyenit](/maintainers/adamnguyenit)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lalu-jer/health.svg)

```
[![Health](https://phpackages.com/badges/lalu-jer/health.svg)](https://phpackages.com/packages/lalu-jer)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M19](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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