FyreError is a free, open-source error handling library for PHP.
Using Composer
composer require fyre/error
In PHP:
use Fyre\Error\ErrorHandler;
Get Exception
Get the current Exception.
$exception = ErrorHandler::getException();
Get Renderer
Get the error renderer.
$renderer = ErrorHandler::getRenderer();
Handle
Handle an Exception.
$response = ErrorHandler::handle($exception);
Register
Register the error handler.
$options
is an array containing configuration options.log
is a boolean indicating whether to log errors, and will default to false.level
is an integer representing theerror_reporting
level.
ErrorHandler::register($options);
Render
Render an Exception.
ErrorHandler::render($exception);
Set Renderer
Set the error renderer.
$renderer
is a Closure that accepts an Exception as the first argument.
ErrorHandler::setRenderer($renderer);
The renderer should return a ClientResponse or a string.
use Fyre\Error\Middleware\ErrorHandlerMiddleware;
$middleware = new ErrorHandlerMiddleware();
Process
$request
is a ServerRequest.$handler
is a RequestHandler.
$response = $middleware->process($request, $handler);
This method will return a ClientResponse.
Custom exceptions can be created by extending the Fyre\Error\Exceptions\Exception
class.
$message
is a string representing the error message.$code
is a number representing the error code, and will default to 500.$previous
is an Exception representing the previous exception, and will default to null.
new Exception($message, $code, $previous);
Bad Request
400 Bad Request error.
use Fyre\Error\Exceptions\BadRequestException;
Unauthorized
401 Unauthorized error.
use Fyre\Error\Exceptions\UnauthorizedException;
Forbidden
403 Forbidden error.
use Fyre\Error\Exceptions\Forbidden;
Not Found
404 Not Found error.
use Fyre\Error\Exceptions\NotFoundException;
Method Not Allowed
405 Method Not Allowed error.
use Fyre\Error\Exceptions\MethodNotAllowedException;
Not Acceptable
406 Not Acceptable error.
use Fyre\Error\Exceptions\NotAcceptableException;
Conflict
409 Conflict error.
use Fyre\Error\Exceptions\ConflictException;
Gone
410 Gone error.
use Fyre\Error\Exceptions\GoneException;
Internal Server
500 Internal Server error.
use Fyre\Error\Exceptions\InternalServerException;
Not Implemented
501 Not Implemented error.
use Fyre\Error\Exceptions\NotImplementedException;
Service Unavailable
503 Service Unavailable error.
use Fyre\Error\Exceptions\ServiceUnavailableException;