2017 © Pedro Peláez
 

library http-exception

HTTP aware exceptions

image

juliangut/http-exception

HTTP aware exceptions

  • Friday, February 16, 2018
  • by juliangut
  • Repository
  • 1 Watchers
  • 1 Stars
  • 72 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 7 % Grown

The README.md

PHP version Latest Version License, (*1)

Build Status Style Check Code Quality Code Coverage, (*2)

Total Downloads Monthly Downloads, (*3)

http-exception

HTTP aware exceptions, (*4)

Installation

Composer

composer require juliangut/http-exception

Usage

Require composer autoload file, (*5)

require './vendor/autoload.php';

HTTP aware exceptions are just like normal exceptions but carrying an HTTP Status Code, (*6)

use Jgut\HttpException\HttpException;

$exceptionMessage = 'You shall not pass!';
$exceptionDescription = 'You do not have permission';
$exceptionCode = 1001; // Internal code
$previousException = new \Exception();
$exception = new BadRequestHttpException($exceptionMessage, $exceptionDescription, $exceptionCode, $previousException);

$exception->getStatusCode(); // 400 Bad Request

Additionally exceptions have a description and a unique identifier which can be used in logging and displaying for example on APIs, allowing you to have more information over the erroneous situation when addressed, (*7)

$exception->getDescription();
$exception->getIdentifier();

Contributing

Found a bug or have a feature request? Please open a new issue. Have a look at existing issues before., (*8)

See file CONTRIBUTING.md, (*9)

License

See file LICENSE included with the source code for a copy of the license terms., (*10)

The Versions