from starlette.exceptions import HTTPException as StarletteHTTPException
from fastapi.exceptions import RequestValidationError
from fastapi import FastAPI

# This file is part of the middleware project.
from middleware.validation import Validation as ValidationMiddleware
from middleware.exceptions.handler import ExceptionHandler

run = FastAPI()

# Middleware for token validation and handler errors
run.add_exception_handler(RequestValidationError, ExceptionHandler.validation_exception)
run.add_exception_handler(StarletteHTTPException, ExceptionHandler.http_exception)
run.add_exception_handler(Exception, ExceptionHandler.generic_exception)
run.add_middleware(ValidationMiddleware)

@run.get("/")
async def root():
    return {"message": "Hello World"}