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:
parent
f7e9c76f64
commit
2eca302234
1 changed files with 19 additions and 13 deletions
|
@ -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"),
|
||||
|
|
Loading…
Reference in a new issue