v2.7.3 (#564)
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:
parent
9c1c32e058
commit
90763daf81
61 changed files with 6046 additions and 694 deletions
46
vibe/core/nuage/exceptions.py
Normal file
46
vibe/core/nuage/exceptions.py
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue