1. Go to this page and download the library: Download phphd/exception-handler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use PhPhD\ExceptionHandler\Middleware\Chain\Escalator\RaiseAs;
#[RaiseAs(AccessDeniedHttpException::class, bus: 'api.exception.bus')]
final class NonWhiteListedUserException extends DomainException
{
}
use PhPhD\ExceptionHandler\Middleware\Chain\Escalator\RaiseAs;
#[RaiseAs(ImportLockedHttpException::class, bus: 'api.exception.bus')]
#[RaiseAs(RecoverableMessageHandlingException::class, bus: 'consumer.exception.bus')]
final class ImportLockedException extends RuntimeException
{
}
#[AsMessageHandler('api.exception.bus')]
final readonly class InventoryExceptionHandler
{
/** @throws Throwable */
public function __invoke(InventoryDomainException $exception, InventoryCommand $command): ?Response
{
if ($exception instanceof JournalHasUnInventoriedItemException) {
$data = $this->formatJournalException($exception);
return new JsonResponse($data, Response::HTTP_BAD_REQUEST);
}
if ($exception instanceof StockItemNotVaildatedException) {
$data = $this->formatItemException($exception, $command->getJournal());
throw new StockItemNotValidatedHttpException($data, $exception);
}
return null;
}
}
#[AsMessageHandler(bus: 'command.exception.bus')]
#[AsMessageHandler(bus: 'query.exception.bus')]
final readonly class InventoryExceptionHandler
{
// ...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.