Exception filters

In Assegai, custom exception handling can be implemented by extending the built-in exception classes, such as Assegai\Core\Exceptions\Http\HttpException.

For example:

src/Exceptions/CustomException.php
use Assegai\Core\Exceptions\Http\HttpException;

class CustomException extends HttpException
{
  function __construct(string $message, int $code = 500)
  {
    parent::__construct($message, $code);
  }
}

To throw this exception, you can use the following code:

throw new CustomException("This ain't it chief", 500);

Customized responses

By default, Assegai's exception layer will automatically send an appropriate user-friendly response when an exception is not handled by the user's application code. However, if you would like to customize the response for a specific exception, you can do so by catching the exception and providing a custom response.

For example:

try {
  // application code here}
catch (CustomException $exception)
{
  // alternatively provide a custom response here  die($exception->getMessage());
}