private function initializeHandler(
        ResourceManager $resourceManager,
        string $resource,
        ApiRequest $request,
        string $checkInterface = null
    )
    {
        $handler = $resourceManager->resolveRequestHandler($resource);
        if ($handler instanceof NeedsAuthenticatedUser && !\Auth::check()) {
            throw new HttpException(401, 'Unauthorized Request');
        }

        if ($checkInterface !== null) {
            if (!$handler instanceof $checkInterface) {
                throw new HttpException(400, 'Bad Request');
            }
        }

        $filterFactory = $resourceManager->resolveFilterFactory($resource);

        $handler
            ->setRequest($request)
            ->setFilters($request->filters())
            ->setFilterFactory($filterFactory);

        return $handler;
    }