protected function getErrorRoute(ServerRequestInterface $request, ResponseInterface $response)
    {
        if (
            interface_exists('Jasny\HttpMessage\GlobalEnvironmentInterface') &&
            $request instanceof GlobalEnvironmentInterface
        ) {
            $request = $request->withoutGlobalEnvironment();
        }
        
        $status = $response->getStatusCode();
        
        $errorUri = $request->getUri()
            ->withPath($status)
            ->withQuery(null)
            ->withFragment(null);
        
        return $this->router->getRoutes()->getRoute($request->withUri($errorUri));
    }