Refactor PostAT.get_status() to handle exceptions when fetching shipment status.

Previously, an API call was made to get the shipment status using the tracking number. The code now incorporates exception handling to log any errors that occur during the fetching of the status. This change ensures that any potential errors are captured and logged for debugging purposes.
This commit is contained in:
Kumi 2023-09-12 09:16:15 +02:00
parent f7e9c76f64
commit 2eca302234
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -2,6 +2,7 @@ from ..classes.provider import BaseProvider
from ..classes.database import Event
import json
import logging
from dateutil.parser import parse
from postat.classes.api import PostAPI
@ -13,6 +14,8 @@ class PostAT(BaseProvider):
def get_status(self, tracking_number, carrier):
api = PostAPI()
try:
status = api.get_shipment_status(tracking_number)
shipment = status["data"]["einzelsendung"]
events = shipment["sendungsEvents"]
@ -28,6 +31,9 @@ class PostAT(BaseProvider):
raw_event=json.dumps(event),
)
except Exception as e:
logging.error(f"Error while fetching status: {e}")
def supported_carriers(self):
return [
("austrian_post", 100, "Austrian Post"),