From 28004b2fc5f1e5519f56640a7f161aa0a94e7ef2 Mon Sep 17 00:00:00 2001 From: marys Date: Mon, 23 Mar 2026 13:48:07 +0100 Subject: [PATCH] Add http error example --- README.md | 0 api/testAPI.py | 20 ++++++++++++++++++-- pyproject.toml | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 README.md create mode 100644 pyproject.toml diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/api/testAPI.py b/api/testAPI.py index 0027e51..8433340 100644 --- a/api/testAPI.py +++ b/api/testAPI.py @@ -1,7 +1,10 @@ from fastapi import ( APIRouter, status, - Body, Depends) + Body, + Depends, + HTTPException +) from influxdb_client.client.influxdb_client_async import InfluxDBClientAsync 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_model: list[ExecutionModel] = await execution_query.get_execution_by_id(id) res = [i.asdict() for i in execution_model] - return {"results": res} \ No newline at end of file + 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 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4ee49f6 --- /dev/null +++ b/pyproject.toml @@ -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", +]