Coverage for src/data_api/api/schemas/errors.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-13 19:28 +0000

1"""Reusable public error responses.""" 

2 

3from typing import Any 

4 

5from pydantic import BaseModel 

6 

7 

8class ErrorResponse(BaseModel): 

9 detail: str 

10 

11 

12class ValidationIssue(BaseModel): 

13 loc: list[str | int] 

14 msg: str 

15 type: str 

16 input: Any = None 

17 ctx: dict[str, Any] | None = None 

18 

19 

20class ValidationErrorResponse(BaseModel): 

21 detail: str | list[ValidationIssue] 

22 

23 

24VALIDATION_ERROR_RESPONSES = { 

25 422: { 

26 "model": ValidationErrorResponse, 

27 "description": "Invalid request parameter, body, or regular expression", 

28 # FastAPI can omit the model-derived content on some platforms. 

29 "content": { 

30 "application/json": {"schema": {"$ref": "#/components/schemas/ValidationErrorResponse"}} 

31 }, 

32 }, 

33} 

34 

35 

36LIVE_ERROR_RESPONSES = { 

37 500: {"model": ErrorResponse, "description": "Unexpected internal error"}, 

38 502: {"model": ErrorResponse, "description": "Upstream unavailable or invalid response"}, 

39 504: {"model": ErrorResponse, "description": "Upstream request timed out"}, 

40}