Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 476d3d1

Browse files
author
Phil Varner
committed
fix exception logging
1 parent 40a208d commit 476d3d1

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ none
2929

3030
### Fixed
3131

32-
none
32+
- Exception logging
3333

3434
### Security
3535

src/stapi_fastapi/routers/product_router.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import logging
44
from typing import TYPE_CHECKING, Self
5-
5+
import traceback
66
from fastapi import APIRouter, HTTPException, Request, Response, status
77
from geojson_pydantic.geometries import Geometry
88
from returns.result import Failure, Success
@@ -22,6 +22,8 @@
2222
if TYPE_CHECKING:
2323
from stapi_fastapi.routers import RootRouter
2424

25+
logger = logging.getLogger(__name__)
26+
2527

2628
class ProductRouter(APIRouter):
2729
def __init__(
@@ -182,7 +184,10 @@ async def search_opportunities(
182184
case Failure(e) if isinstance(e, ConstraintsException):
183185
raise e
184186
case Failure(e):
185-
logging.exception("An error occurred while searching opportunities", e)
187+
logger.exception(
188+
"An error occurred while searching opportunities: %s",
189+
traceback.format_exception(e),
190+
)
186191
raise HTTPException(
187192
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
188193
detail="Error searching opportunities",
@@ -221,7 +226,10 @@ async def create_order(
221226
case Failure(e) if isinstance(e, ConstraintsException):
222227
raise e
223228
case Failure(e):
224-
logging.exception("An error occurred while creating order", e)
229+
logger.exception(
230+
"An error occurred while creating order: %s",
231+
traceback.format_exception(e),
232+
)
225233
raise HTTPException(
226234
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
227235
detail="Error creating order",

src/stapi_fastapi/routers/root_router.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from typing import Self
3-
3+
import traceback
44
from fastapi import APIRouter, HTTPException, Request, status
55
from fastapi.datastructures import URL
66
from fastapi.responses import Response
@@ -23,6 +23,8 @@
2323
from stapi_fastapi.responses import GeoJSONResponse
2424
from stapi_fastapi.routers.product_router import ProductRouter
2525

26+
logger = logging.getLogger(__name__)
27+
2628

2729
class RootRouter(APIRouter):
2830
def __init__(
@@ -176,7 +178,10 @@ async def get_orders(self, request: Request) -> OrderCollection:
176178
)
177179
return orders
178180
case Failure(e):
179-
logging.exception("An error occurred while retrieving orders", e)
181+
logger.exception(
182+
"An error occurred while retrieving orders: %s",
183+
traceback.format_exception(e),
184+
)
180185
raise HTTPException(
181186
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
182187
detail="Error finding Orders",
@@ -195,8 +200,9 @@ async def get_order(self: Self, order_id: str, request: Request) -> Order:
195200
case Success(Maybe.empty):
196201
raise NotFoundException("Order not found")
197202
case Failure(e):
198-
logging.exception(
199-
f"An error occurred while retrieving order '{order_id}'", e
203+
logger.exception(
204+
"An error occurred while retrieving order '%s': %s", order_id,
205+
traceback.format_exception(e),
200206
)
201207
raise HTTPException(
202208
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
@@ -226,8 +232,9 @@ async def get_order_statuses(
226232
],
227233
)
228234
case Failure(e):
229-
logging.exception(
230-
"An error occurred while retrieving order statuses", e
235+
logger.exception(
236+
"An error occurred while retrieving order statuses: %s",
237+
traceback.format_exception(e),
231238
)
232239
raise HTTPException(
233240
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
@@ -243,7 +250,10 @@ async def set_order_status(
243250
case Success(_):
244251
return Response(status_code=status.HTTP_202_ACCEPTED)
245252
case Failure(e):
246-
logging.exception("An error occurred while setting order status", e)
253+
logger.exception(
254+
"An error occurred while setting order status: %s",
255+
traceback.format_exception(e),
256+
)
247257
raise HTTPException(
248258
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
249259
detail="Error setting Order Status",

0 commit comments

Comments
 (0)