from typing import Any, Optional, Dict

from fastapi import Request
from fastapi.responses import JSONResponse


class HTTPException(Exception):

    def __init__(
        self,
        status_code: int,
        content: Any = None,
        headers: Optional[Dict[str, Any]] = None,
    ) -> None:
        
        self.status_code = status_code
        self.content = content
        self.headers = headers

    def __repr__(self) -> str:
        """Class custom __repr__ method implementation.

        Returns:
            str: HTTPException string object.

        """
        kwargs = []

        for key, value in self.__dict__.items():
            if not key.startswith("_"):
                kwargs.append(f"{key}={value!r}")

        return f"{self.__class__.__name__}({', '.join(kwargs)})"


async def http_exception_handler(request: Request, exception: HTTPException) -> JSONResponse:

    return JSONResponse(
        status_code=exception.status_code,
        content=exception.content,
        headers=exception.headers,
    )
