2017 © Pedro Peláez
 

library crash-pad

image

avalanche-development/crash-pad

  • Thursday, December 29, 2016
  • by jacobemerick
  • Repository
  • 1 Watchers
  • 0 Stars
  • 445 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

crash-pad

Error handler that utilizes peel exceptions to standardize responses., (*1)

Build Status Code Climate Test Coverage, (*2)

Installation

It's recommended that you use Composer to install crash-pad., (*3)

$ composer require avalanche-development/crash-pad

crash-pad requires PHP 5.6 or newer., (*4)

Usage

This handler works best with peel. It can work without, but without the HttpErrorInterface exceptions all of the responses are going to default as 500 Server Errors., (*5)

Depending on the framework you're using, this can be hooked up in a few different ways. In Slim you'd attach it to the Slim\Container. I'm going to be biased and show this in Talus., (*6)

$talus = new Talus([...]);
$talus->setErrorHandler(new AvalancheDevelopment\CrashPad\ErrorHandler);

This will listen for exceptions that jump out of the call stack and return appropriate responses. For example, if you have some middleware like so..., (*7)

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
}

The error handler will detect the AvalancheDevelopment\Peel\HttpErrorInterface exception and return a response like so..., (*8)

{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "Invalid JSON"
}

All responses will include these three fields, plus the appropriate headers. Any exceptions that do not implement the HttpErrorEnterface will respond the default 500., (*9)

Development

This library is in active development. Some of the error responses may include metadata moving forward., (*10)

Tests

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

$ phpunit

License

crash-pad is licensed under the MIT license. See License File for more information., (*12)

The Versions

16/11 2016
12/11 2016

0.2.1

0.2.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar jacobemerick

07/11 2016

0.2.0

0.2.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar jacobemerick

02/11 2016

0.1.1

0.1.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar jacobemerick

01/11 2016

0.1.0

0.1.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar jacobemerick