Co-authored-by: Bastien <bastien.baret@gmail.com>
Co-authored-by: Laure Hugo <201583486+laure0303@users.noreply.github.com>
Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com>
Co-authored-by: Paul Cacheux <paul.cacheux@mistral.ai>
Co-authored-by: Val <102326092+vdeva@users.noreply.github.com>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Clément Drouin 2026-04-03 15:56:50 +02:00 committed by GitHub
parent 9c1c32e058
commit 90763daf81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
61 changed files with 6046 additions and 694 deletions

View file

@ -0,0 +1,46 @@
from __future__ import annotations
from enum import StrEnum
from http import HTTPStatus
import httpx
class ErrorCode(StrEnum):
TEMPORAL_CONNECTION_ERROR = "temporal_connection_error"
GET_EVENTS_STREAM_ERROR = "get_events_stream_error"
POST_EXECUTIONS_SIGNALS_ERROR = "post_executions_signals_error"
POST_EXECUTIONS_UPDATES_ERROR = "post_executions_updates_error"
GET_EXECUTIONS_ERROR = "get_executions_error"
class WorkflowsException(Exception):
def __init__(
self,
message: str,
status: HTTPStatus = HTTPStatus.INTERNAL_SERVER_ERROR,
code: ErrorCode = ErrorCode.TEMPORAL_CONNECTION_ERROR,
) -> None:
self.status = status
self.message = message
self.code = code
def __str__(self) -> str:
return f"{self.message} (code={self.code}, status={self.status.value})"
@classmethod
def from_api_client_error(
cls,
exc: Exception,
message: str = "HTTP request failed",
code: ErrorCode = ErrorCode.TEMPORAL_CONNECTION_ERROR,
) -> WorkflowsException:
status = HTTPStatus.INTERNAL_SERVER_ERROR
if isinstance(exc, httpx.HTTPStatusError):
try:
status = HTTPStatus(exc.response.status_code)
except ValueError:
pass
if isinstance(exc, httpx.ConnectError | httpx.TimeoutException):
status = HTTPStatus.BAD_GATEWAY
return cls(message=f"{message}: {exc}", code=code, status=status)