juliangut / http-exception
HTTP aware exceptions
Installs: 5 359
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.0
- fig/http-message-util: ^1.1
- pascaldevink/shortuuid: ^1.0
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.1
- editorconfig-checker/editorconfig-checker: ^7.0
- friendsofphp/php-cs-fixer: ^2.0
- infection/infection: ^0.7.0
- phpmd/phpmd: ^2.0
- phpmetrics/phpmetrics: ^2.0
- phpstan/phpstan: ^0.9
- phpstan/phpstan-strict-rules: 0.9
- phpunit/phpunit: ^5.7|^6.0
- povils/phpmnd: ^1.1
- roave/security-advisories: dev-master
- sebastian/phpcpd: ^2.0
- squizlabs/php_codesniffer: ^2.0
This package is auto-updated.
Last update: 2024-11-15 11:40:27 UTC
README
http-exception
HTTP aware exceptions
Installation
Composer
composer require juliangut/http-exception
Usage
Require composer autoload file
require './vendor/autoload.php';
HTTP aware exceptions are just like normal exceptions but carrying an HTTP Status Code
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
$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.
See file CONTRIBUTING.md
License
See file LICENSE included with the source code for a copy of the license terms.