MCPcopy Create free account
hub / github.com/Harmeet10000/AgentNexus-LangChain-FastAPI / APIException

Class APIException

src/app/utils/exceptions.py:9–40  ·  view source on GitHub ↗

Base exception for all **handled/known** API errors. All user-facing error responses should inherit from this class (or use its subclasses) so they get consistent formatting.

Source from the content-addressed store, hash-verified

7
8
9class APIException(HTTPException):
10 """
11 Base exception for all **handled/known** API errors.
12
13 All user-facing error responses should inherit from this class
14 (or use its subclasses) so they get consistent formatting.
15 """
16
17 def __init__(
18 self,
19 status_code: int,
20 detail: str,
21 error_code: str | None = None,
22 data: Any = None,
23 headers: dict[str, str] | None = None,
24 ):
25 self.error_code = error_code or self.__class__.__name__.replace("Exception", "").upper()
26 self.data = data
27
28 # We put everything inside 'detail' so the frontend gets a rich object
29 rich_detail = {
30 "message": detail,
31 "error_code": self.error_code,
32 }
33 if data is not None:
34 rich_detail["data"] = data
35
36 super().__init__(
37 status_code=status_code,
38 detail=rich_detail,
39 headers=headers,
40 )
41
42
43# ────────────────────────────────────────

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected