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

Commit 122164c

Browse files
author
Phil Varner
committed
use get_orders correctly
1 parent b50795b commit 122164c

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

src/stapi_fastapi/routers/product_router.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import logging
34
from typing import TYPE_CHECKING, Self
45

56
from fastapi import APIRouter, HTTPException, Request, Response, status
@@ -179,8 +180,10 @@ async def search_opportunities(
179180
case Failure(Some(e)) if isinstance(e, ConstraintsException):
180181
raise e
181182
case Failure(Some(e)):
183+
logging.exception("An error occurred while searching opportunities", e)
182184
raise HTTPException(
183-
status.HTTP_500_INTERNAL_SERVER_ERROR, detail=e.detail
185+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
186+
detail="Error searching opportunities",
184187
)
185188
case Failure(Maybe.empty):
186189
raise HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR)
@@ -218,8 +221,10 @@ async def create_order(
218221
case Failure(Some(e)) if isinstance(e, ConstraintsException):
219222
raise e
220223
case Failure(Some(e)):
224+
logging.exception("An error occurred while creating order", e)
221225
raise HTTPException(
222-
status.HTTP_500_INTERNAL_SERVER_ERROR, detail=e.detail
226+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
227+
detail="Error creating order",
223228
)
224229
case Failure(Maybe.empty):
225230
raise HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR)

src/stapi_fastapi/routers/root_router.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,31 @@ def get_products(self, request: Request) -> ProductsCollection:
138138
)
139139

140140
async def get_orders(self, request: Request) -> OrderCollection:
141-
orders = await self.backend.get_orders(request)
142-
for order in orders:
143-
order.links.append(
144-
Link(
145-
href=str(
146-
request.url_for(f"{self.name}:get-order", order_id=order.id)
147-
),
148-
rel="self",
149-
type=TYPE_JSON,
141+
match await self.backend.get_orders(request):
142+
case Success(orders):
143+
for order in orders:
144+
order.links.append(
145+
Link(
146+
href=str(
147+
request.url_for(
148+
f"{self.name}:get-order", order_id=order.id
149+
)
150+
),
151+
rel="self",
152+
type=TYPE_JSON,
153+
)
154+
)
155+
return orders
156+
case Failure(Maybe.empty):
157+
raise NotFoundException("Orders not found")
158+
case Failure(Some(e)):
159+
logging.exception("An error occurred while retrieving orders", e)
160+
raise HTTPException(
161+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
162+
detail="Error finding Orders",
150163
)
151-
)
152-
153-
return orders
164+
case _:
165+
raise AssertionError("Expected code to be unreachable")
154166

155167
async def get_order(self: Self, order_id: str, request: Request) -> Order:
156168
"""

0 commit comments

Comments
 (0)