Download the PHP package aatis/error-handler without Composer
On this page you can find all versions of the php package aatis/error-handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package error-handler
Aatis EH
Installation
Usage
Initialization
To initialize the error handler, you need to pass the following parameters:
- a logger service that implements the
Psr\Log\LoggerInterface
- an instance of
ErrorCodeBag
service of the package - an instance of
ExceptionCodeBag
service of the package
Logger
Each time an error is triggered or an exception is thrown, the ErrorHandler
will log a message with the logger service you provided.
ErrorCodeBag
The ErrorCodeBag
service store 15 error codes corresponding to the 15 error levels of PHP :
- 1 => 'E_ERROR'
- 2 => 'E_WARNING'
- 4 => 'E_PARSE'
- 8 => 'E_NOTICE'
- 16 => 'E_CORE_ERROR'
- 32 => 'E_CORE_WARNING'
- 64 => 'E_COMPILE_ERROR'
- 128 => 'E_COMPILE_WARNING'
- 256 => 'E_USER_ERROR'
- 512 => 'E_USER_WARNING'
- 1024 => 'E_USER_NOTICE'
- 2048 => 'E_STRICT'
- 4096 => 'E_RECOVERABLE_ERROR'
- 8192 => 'E_DEPRECATED'
- 16384 => 'E_USER_DEPRECATED'
You can not add or override any error codes from this bag.
ExceptionCodeBag
The ExceptionCodeBag
service store any sort of exception code you want to use in your application. By default, a list with all the 400 and 500 error codes is provided, but you can extand and/or override it :
- 0 => 'Basic Error'
- 400 => 'Bad Request'
- 401 => 'Unauthorized'
- 402 => 'Payment Required Experimental'
- 403 => 'Forbidden'
- 404 => 'Not Found'
- 405 => 'Method Not Allowed'
- 406 => 'Not Acceptable'
- 407 => 'Proxy Authentication Required'
- 408 => 'Request Timeout'
- 409 => 'Conflict'
- 410 => 'Gone'
- 411 => 'Length Required'
- 412 => 'Precondition Failed'
- 413 => 'Payload Too Large'
- 414 => 'URI Too Long'
- 415 => 'Unsupported Media Type'
- 416 => 'Range Not Satisfiable'
- 417 => 'Expectation Failed'
- 418 => 'I\'m a teapot'
- 421 => 'Misdirected Request'
- 422 => 'Unprocessable Content'
- 423 => 'Locked'
- 424 => 'Failed Dependency'
- 425 => 'Too Early Experimental'
- 426 => 'Upgrade Required'
- 428 => 'Precondition Required'
- 429 => 'Too Many Requests'
- 431 => 'Request Header Fields Too Large'
- 451 => 'Unavailable For Legal Reasons'
- 500 => 'Internal Server Error'
- 501 => 'Not Implemented'
- 502 => 'Bad Gateway'
- 503 => 'Service Unavailable'
- 504 => 'Gateway Timeout'
- 505 => 'HTTP Version Not Supported'
- 506 => 'Variant Also Negotiates'
- 507 => 'Insufficient Storage'
- 508 => 'Loop Detected'
- 510 => 'Not Extended'
- 511 => 'Network Authentication Required'
You can add or override any error codes from this bag by creating a custom string enum like the following template :
Then, pass it to the ExceptionCodeBag
.
You can pass as many enums as you want into it constructor
To pass a specific code to an exception, you can do the following :
With Aatis Framework
Requirements
Add the ErrorCodeBag
and ExceptionCodeBag
services to the Container
:
ExceptionCodeBag
If you want to add or override any error codes from the ExceptionCodeBag
, you can do the following :