File size: 628 Bytes
fe948cf
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"""Small errors mapped at the API boundary, without leaking private fixture data."""
class GatewayError(Exception):
    def __init__(self, status: int, code: str, message: str, details: dict | None = None):
        self.status = status
        self.code = code
        self.message = message
        self.details = details or {}
        super().__init__(message)

def missing():
    return GatewayError(404, "RESOURCE_NOT_FOUND", "资源不存在或无权访问。")

def conflict(code="VERSION_CONFLICT", message="资源版本已改变,请刷新后重试。", **details):
    return GatewayError(409, code, message, details)