Skip to content

Commit ccb9c99

Browse files
committed
fix: handle empty response in Freightcom shipment creation
- Add failsafe handling for empty responses to prevent errors in shipment ID extraction. - Ensure deserialization fallback to empty JSON if response is missing.
1 parent 19533a7 commit ccb9c99

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

  • plugins/freightcom_rest/karrio/mappers/freightcom_rest

plugins/freightcom_rest/karrio/mappers/freightcom_rest/proxy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ def create_shipment(self, request: lib.Serializable) -> lib.Deserializable:
5151
response = self._send_request(
5252
path="/shipment", request=lib.Serializable(request.value, lib.to_json)
5353
)
54+
response_dict = lib.failsafe(lambda: lib.to_dict(response)) or {}
55+
shipment_id = response_dict.get('id')
5456

55-
shipment_id = lib.to_dict(response).get('id')
5657
if not shipment_id:
57-
return lib.Deserializable(response, lib.to_dict)
58-
58+
return lib.Deserializable(response if response else "{}", lib.to_dict)
5959

6060
# Step 2: retry because api return empty bytes if done to fast
6161
time.sleep(1)

0 commit comments

Comments
 (0)