Hello!
Please tell me how can I apply “try catch” inside a group of routes.
Now I have this:
$app->group(’/v1’, function (\Slim\Routing\RouteCollectorProxy $group) {
$group->get('/', IndexController::class.":index");
$group->post('/upload', MyController::class.":upload");
})->add(new ResultMiddleware());
And inside the UploadController have “try catch” block
But now I have to add this block to each controller so that it works for all controllers within the group.
I would want something that could work something like this:
$app->group('/v1', function (\Slim\Routing\RouteCollectorProxy $group) {
try {
$group->get('/', IndexController::class . ":index");
$group->post('/upload', MyController::class . ":upload");
}
catch (Exception $exception) {
// $response = $response->withStatus($exception->getCode());
// $response->getBody()->write($exception->getMessage());
//
// $this->logger->error( $exception->getMessage() );
}
})->add(new ResultMiddleware());
How can I do this?
Thanks for help