Add http error example
This commit is contained in:
+18
-2
@@ -1,7 +1,10 @@
|
|||||||
from fastapi import (
|
from fastapi import (
|
||||||
APIRouter,
|
APIRouter,
|
||||||
status,
|
status,
|
||||||
Body, Depends)
|
Body,
|
||||||
|
Depends,
|
||||||
|
HTTPException
|
||||||
|
)
|
||||||
from influxdb_client.client.influxdb_client_async import InfluxDBClientAsync
|
from influxdb_client.client.influxdb_client_async import InfluxDBClientAsync
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
@@ -62,4 +65,17 @@ async def get_mysql_by_id(id: int, db: AsyncSession = Depends(get_mysql_db)):
|
|||||||
execution_query = ExecutionQueryAsync(db)
|
execution_query = ExecutionQueryAsync(db)
|
||||||
execution_model: list[ExecutionModel] = await execution_query.get_execution_by_id(id)
|
execution_model: list[ExecutionModel] = await execution_query.get_execution_by_id(id)
|
||||||
res = [i.asdict() for i in execution_model]
|
res = [i.asdict() for i in execution_model]
|
||||||
return {"results": res}
|
return {"results": res}
|
||||||
|
|
||||||
|
@router.get(
|
||||||
|
path="/get_error/{issue}",
|
||||||
|
name='get error',
|
||||||
|
responses={
|
||||||
|
status.HTTP_401_UNAUTHORIZED: {},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
async def get_error(issue: bool = True):
|
||||||
|
print(f"{issue=}")
|
||||||
|
if issue:
|
||||||
|
raise HTTPException(status_code=500, detail={'error':'b'})
|
||||||
|
return True
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
[project]
|
||||||
|
name = "fastapi-async"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Add your description here"
|
||||||
|
requires-python = ">=3.13"
|
||||||
|
dependencies = [
|
||||||
|
"aiocsv>=1.4.0",
|
||||||
|
"aiohttp>=3.13.3",
|
||||||
|
"aiomysql>=0.3.2",
|
||||||
|
"fastapi>=0.135.1",
|
||||||
|
"influxdb-client>=1.50.0",
|
||||||
|
"sqlalchemy>=2.0.48",
|
||||||
|
"uvicorn>=0.42.0",
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user