Skip to content

[Feature] Add a custom HTTP exception class file #79

@SeanTshark

Description

@SeanTshark

Issue Type

  • Bug report
  • Feature request
  • Documentation update
  • Other (please specify)

Description

Currently the repository doesn't have a class to handle mass HTTPExpection checks. Adding a custom class/classes to handle the various HTTPExpection checks will help in minimizing code lines as the class will only need to be called with the variable attached to it.

Screenshots

Here is an example of what I mean that could be handled by the custom class.

Currently it has a lot of if statements to check specific HTTPExceptions, this bloats the line count, when creating the custom class, it will handle the logic and the user can add their own custom message that overrides the default one.

File Path: app/mcp/mcp_tools/miles_to_km.py
Method Name: def miles_to_kilometers_value(miles: float) -> float:
Code lines: 44 - 63

if miles is None:
    raise HTTPException(status_code=422, detail="Miles is required.")
if not isinstance(miles, (int, float)):
    raise HTTPException(status_code=422, detail="Miles must be a numeric value.")
if math.isnan(miles) or math.isinf(miles):
    raise HTTPException(status_code=422, detail="Miles must be a finite number.")
if miles <= 0:
    raise HTTPException(
        status_code=422, detail="Distance must be greater than zero."
    )
if miles < 0.0001:  # noqa: PLR2004
    raise HTTPException(
        status_code=422, detail="Distance is too small to be meaningful."
    )
if miles > MAX_TUTORIAL_MILES:
    raise HTTPException(
        status_code=422,
        detail="Distance is unrealistically large for this tutorial example.",
    )

Possible Solution

ApiExceptionClass:
It will cover HTTP status codes and logic to raise the Exceptions for them, providing a message to describe what issue had occurred.
link to HTTP status codes: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status

MCPExceptionClass:
It will cover the MCP status codes that are thrown when an issue happens with the MCP server client.
Link to MCP status codes: https://www.mcpevals.io/blog/mcp-error-codes

Metadata

Metadata

Assignees

Labels

DXIssue would improve the developer experienceenhancementNew feature or request

Projects

Status
Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions