Spaces:
Sleeping

headless_scilab / app /errors.py
GitHub Copilot
Update tests and align Scilab space implementation
cdbd2a0
Raw History Blame Contribute Delete
856 Bytes
from __future__ import annotations
from enum import Enum
from typing import Any
class ErrorCode(str, Enum):
NETWORK = "XCOS_ERR_NETWORK"
TIMEOUT = "XCOS_ERR_VALIDATION_TIMEOUT"
VALIDATION_FAILED = "XCOS_ERR_VALIDATION_FAILED"
CANCELLED = "XCOS_ERR_CANCELLED"
UNAUTHORIZED = "XCOS_ERR_UNAUTHORIZED"
BAD_REQUEST = "XCOS_ERR_BAD_REQUEST"
INTERNAL = "XCOS_ERR_INTERNAL"
SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE"
def error_payload(
code: ErrorCode,
message: str,
*,
correlation_id: str,
details: dict[str, Any] | None = None,
) -> dict[str, Any]:
payload: dict[str, Any] = {
"error": {
"code": code.value,
"message": message,
},
"correlation_id": correlation_id,
}
if details:
payload["error"]["details"] = details
return payload