mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-20 20:09:05 -05:00
16 lines
369 B
Python
16 lines
369 B
Python
from fastapi import FastAPI
|
|
from starlette.exceptions import HTTPException
|
|
from starlette.responses import PlainTextResponse
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.exception_handler(HTTPException)
|
|
async def http_exception(request, exc):
|
|
return PlainTextResponse(str(exc.detail), status_code=exc.status_code)
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "Hello World"}
|