This commit is contained in:
gsinghpal
2026-05-21 03:37:25 -04:00
parent b2f483d67c
commit 1314f4581d
47 changed files with 5730 additions and 177 deletions

View File

@@ -165,7 +165,21 @@ class FedexRequest:
def _process_errors(self, res_body):
err_msgs = []
for err in res_body.get('errors', []):
err_msgs.append(f"{err['message']} ({err['code']})")
msg = f"{err.get('message', '')} ({err.get('code', '')})"
# FedEx hides the specific field-validation failures in
# parameterList (e.g. INVALID.INPUT.EXCEPTION's top-level
# message is just "Validation failed for object='X'. Error
# count: 1" — the actual field name lives in parameterList).
# Surface them so operators see "city cannot be null" instead
# of a useless generic exception.
params = err.get('parameterList') or []
details = '; '.join(
f"{p.get('key', '')}={p.get('value', '')}"
for p in params if p.get('key') or p.get('value')
)
if details:
msg += f"\n {details}"
err_msgs.append(msg)
return ','.join(err_msgs)
def _process_alerts(self, response):
@@ -395,7 +409,8 @@ class FedexRequest:
self._strip_customs_for_domestic(request_data)
res = self._send_fedex_request("/rate/v1/rates/quotes", request_data)
try:
rate = next(filter(lambda d: d['currency'] == fedex_currency, res['rateReplyDetails'][0]['ratedShipmentDetails']), {})
reply = res['rateReplyDetails'][0]
rate = next(filter(lambda d: d['currency'] == fedex_currency, reply['ratedShipmentDetails']), {})
if rate.get('totalNetChargeWithDutiesAndTaxes', 0):
price = rate['totalNetChargeWithDutiesAndTaxes']
else:
@@ -403,8 +418,22 @@ class FedexRequest:
except KeyError:
raise ValidationError(_('Could not decode response')) from None
# Commit info — service display name + estimated delivery date
# for the receiving form's shipping-quote preview panel.
# FedEx returns several shapes depending on service; fall
# through gracefully so callers that only need `price` still
# work.
commit = reply.get('commit') or {}
date_detail = commit.get('dateDetail') or {}
return {
'price': price,
'currency': fedex_currency,
'service_type': reply.get('serviceType') or self.service_type,
'service_name': reply.get('serviceName') or '',
'delivery_timestamp': commit.get('deliveryTimestamp')
or date_detail.get('dayCxsFormat') or '',
'day_of_week': commit.get('dayOfWeek') or '',
'transit_time': commit.get('transitTime') or '',
'alert_message': self._process_alerts(res),
}