File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ class CommonInventoryQueryParams:
1111
1212 valid_models = [
1313 r"^Ioniq(%20|\+|\s|\-)5((%20|\+|\-)N)?$" , # Hyundai Ioniq 5 and 5 N # noqa: W605
14- r"^Ioniq(%20|\+|\s|\-)6 $" , # Hyundai Ioniq 6 # noqa: W605
14+ r"^Ioniq(%20|\+|\s|\-)(6|9) $" , # Hyundai Ioniq 6, 9 # noqa: W605
1515 r"^Kona(%20|\+|\s)Ev$" , # Hyundai Kona EV # noqa: W605
1616 "^N$" , # Kia EV6
1717 "^V$" , # Kia Niro EV
@@ -45,8 +45,8 @@ def __init__(
4545 self ,
4646 # https://facts.usps.com/42000-zip-codes/. Starting zip code is 00501
4747 zip : int = Query (ge = 501 , le = 99950 ),
48- year : int = Query (ge = 2022 , le = 2025 ),
49- radius : int = Query (gt = 0 , lt = 1000 ),
48+ year : int = Query (ge = 2022 , le = 2026 ),
49+ radius : int = Query (gt = 0 , lt = 500 ),
5050 model : str = Query (pattern = "|" .join (valid_models )),
5151 ):
5252 # Zip is passed in as a query parameter string. When casting to an int, the
Original file line number Diff line number Diff line change 11from fastapi import APIRouter , Depends , Request
22
33from src .libs .common_query_params import CommonInventoryQueryParams
4- from src .libs .responses import error_response , send_response
54from src .libs .http import AsyncHTTPClient
5+ from src .libs .responses import error_response , send_response
66
77router = APIRouter (prefix = "/api" )
88verify_ssl = True
@@ -53,6 +53,15 @@ async def get_hyundai_inventory(
5353 if "SUCCESS" in inventory ["status" ]:
5454 return send_response (response_data = inventory )
5555 else :
56+ # If the API response does not have a data key, there is no inventory.
57+ # Return an empty dict response which the UI will use to display the no inventory
58+ # message. This most commonly occurs when the user selects a year that is not
59+ # valid for a selected model.
60+ try :
61+ inventory ["data" ]
62+ except KeyError :
63+ return send_response (response_data = {})
64+
5665 try :
5766 error_message = inventory .text
5867 except AttributeError :
You can’t perform that action at this time.
0 commit comments