From 9476cd6994a035744716ada34f4a23532a5feccc Mon Sep 17 00:00:00 2001 From: PleahMaCaka Date: Thu, 2 Nov 2023 15:10:56 +0900 Subject: [PATCH] fix(subway): error handling with skills learned by alien in the kaper-b66 --- routers/subway.py | 11 +++++++---- service/subway/dto/subway_arrival_dto.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/routers/subway.py b/routers/subway.py index 450eb46..2e4bbf2 100644 --- a/routers/subway.py +++ b/routers/subway.py @@ -29,7 +29,10 @@ def request_subway_data(station_name: str): station_name, ) ) - - data = SubwayArrivalDto.from_json(json.loads(response.text)) - data.items.sort(key=lambda x: x.pred_sec) - return data + try: + data = SubwayArrivalDto.from_json(json.loads(response.text)) + data.items.sort(key=lambda x: x.pred_sec) + return data + except Exception as e: + print(F"역을 찾을 수 없습니다: {e}") + return None diff --git a/service/subway/dto/subway_arrival_dto.py b/service/subway/dto/subway_arrival_dto.py index cd26355..a262ca6 100644 --- a/service/subway/dto/subway_arrival_dto.py +++ b/service/subway/dto/subway_arrival_dto.py @@ -15,7 +15,7 @@ def __init__( @classmethod def from_json(cls, data: dict): - error_msg = data.get["errorMessage"] + error_msg = data["errorMessage"] return cls( error_msg=SubwayErrorMsgDto.from_json( error_msg if error_msg is not None else data