0.3.0 2016-12-29 11:39 UTC

This package is not auto-updated.

Last update: 2020-01-10 16:01:04 UTC


README

An exception library that can be used to bubble up specific http errors through middleware.

Build Status Code Climate Test Coverage

Installation

It's recommended that you use Composer to install peel.

$ composer require avalanche-development/peel

peel requires PHP 5.6 or newer.

Usage

function someMiddleware($request, $response, $next) {
    $body = (string) $request->getBody();
    $body = json_decode($value);
    if (json_last_error() !== JSON_ERROR_NONE) {
        throw new AvalancheDevelopment\Peel\HttpError\BadRequest('Invalid JSON');
    }
    // etc
}

Each exception implements AvalancheDevelopment\Peel\HttpErrorInterface, which enforces two methods, getStatusCode and getStatusMessage. These give you the expected HTTP code and message for any sort of error handler.

Exceptions

Note: see avalanche-development/crash-pad for an error handler that takes advantage of these standardized exceptions.

Development

This library is a work in progress - there may be additional options (like, error metadata) added for different statuses as needed.

Tests

To execute the test suite, you'll need phpunit (and to install package with dev dependencies).

$ phpunit

License

peel is licensed under the MIT license. See License File for more information.