Spaces:
Sleeping

File size: 856 Bytes
cdbd2a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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