mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
feat: Add timeout handling for Slack repo query (#13249)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -3,12 +3,13 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any
|
||||
|
||||
from httpx import AsyncClient, HTTPError, HTTPStatusError
|
||||
from httpx import AsyncClient, HTTPError, HTTPStatusError, TimeoutException
|
||||
from pydantic import SecretStr
|
||||
|
||||
from openhands.core.logger import openhands_logger as logger
|
||||
from openhands.integrations.service_types import (
|
||||
AuthenticationError,
|
||||
ProviderTimeoutError,
|
||||
RateLimitError,
|
||||
RequestMethod,
|
||||
ResourceNotFoundError,
|
||||
@@ -93,7 +94,13 @@ class HTTPClient(ABC):
|
||||
logger.warning(f'Status error on {self.provider} API: {e}')
|
||||
return UnknownException(f'Unknown error: {e}')
|
||||
|
||||
def handle_http_error(self, e: HTTPError) -> UnknownException:
|
||||
def handle_http_error(
|
||||
self, e: HTTPError
|
||||
) -> ProviderTimeoutError | UnknownException:
|
||||
"""Handle general HTTP errors."""
|
||||
logger.warning(f'HTTP error on {self.provider} API: {type(e).__name__} : {e}')
|
||||
if isinstance(e, TimeoutException):
|
||||
return ProviderTimeoutError(
|
||||
f'{self.provider} API request timed out: {type(e).__name__}'
|
||||
)
|
||||
return UnknownException(f'HTTP error {type(e).__name__} : {e}')
|
||||
|
||||
@@ -35,6 +35,7 @@ from openhands.integrations.service_types import (
|
||||
InstallationsService,
|
||||
MicroagentParseError,
|
||||
PaginatedBranchesResponse,
|
||||
ProviderTimeoutError,
|
||||
ProviderType,
|
||||
Repository,
|
||||
ResourceNotFoundError,
|
||||
@@ -258,9 +259,10 @@ class ProviderHandler:
|
||||
per_page: int | None,
|
||||
installation_id: str | None,
|
||||
) -> list[Repository]:
|
||||
"""Get repositories from providers"""
|
||||
"""
|
||||
Get repositories from providers
|
||||
"""Get repositories from providers.
|
||||
|
||||
Raises:
|
||||
ProviderTimeoutError: If a timeout occurs while fetching repos.
|
||||
"""
|
||||
if selected_provider:
|
||||
if not page or not per_page:
|
||||
@@ -277,6 +279,9 @@ class ProviderHandler:
|
||||
service = self.get_service(provider)
|
||||
service_repos = await service.get_all_repositories(sort, app_mode)
|
||||
all_repos.extend(service_repos)
|
||||
except ProviderTimeoutError:
|
||||
# Propagate timeout errors so callers can handle them appropriately
|
||||
raise
|
||||
except Exception as e:
|
||||
logger.warning(f'Error fetching repos from {provider}: {e}')
|
||||
|
||||
|
||||
@@ -191,6 +191,12 @@ class RateLimitError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
class ProviderTimeoutError(ValueError):
|
||||
"""Raised when a request to a git provider times out."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class ResourceNotFoundError(ValueError):
|
||||
"""Raised when a requested resource (file, directory, etc.) is not found."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user