protected function setErrorHandler(Container $container): callable
    {
        return function (Container $container) {
            return function (ServerRequestInterface $request, ResponseInterface $response, Throwable $e) use ($container) {
                $container->sentry->captureException($e);
                if ($container->has('appErrorHandler')) {
                    return $container['appErrorHandler']->error500($request, $response, $e);
                }

                return $response->withStatus(500);
            };
        };
    }