error-handler icon indicating copy to clipboard operation
error-handler copied to clipboard

Add support classes for exception map in `ExceptionResponder`

Open vjik opened this issue 3 years ago • 0 comments

It can make several ways.

One / Container + Callable

Configuration:

$exceptionMap = [
    MyNotFoundException::class => MyExceptionHandler::class,
];

Handling: get MyExceptionHandler class from container and run as callable (use __invoke()) via injector.

Two / Container + Interface

Configuration:

$exceptionMap = [
    MyNotFoundException::class => MyExceptionHandler::class,
];

Add new interface ExceptionHandlerInterface with method createResponse(Throwable $e): ResponseInterface.

Handling: get MyExceptionHandler class from container and run createResponse().

Three / Array Definition + Callable

Add support of array definitions:

$exceptionMap = [
    MyNotFoundException::class => [
        'class' => MyExceptionHandler::class,
        '__construct()' => [ ... ],
    ],
];

Handling: resolve array definition via yiisoft/definitions and run as callable (use __invoke()) via injector.

Four / Array Definition + Interface

Add support of array definitions:

$exceptionMap = [
    MyNotFoundException::class => [
        'class' => MyExceptionHandler::class,
        '__construct()' => [ ... ],
    ],
];

Add new interface ExceptionHandlerInterface with method createResponse(Throwable $e): ResponseInterface.

Handling: resolve array definition via yiisoft/definitions and run createResponse().

vjik avatar Jun 14 '22 10:06 vjik