diff --git a/inema/wpint.py b/inema/wpint.py index 9cfef27..01455c3 100644 --- a/inema/wpint.py +++ b/inema/wpint.py @@ -271,19 +271,24 @@ class WarenpostInt(object): order = self.build_order(items, contact_name=contact_name, order_status=order_status) _logger.info("Order Request: %s", order) r = self.request('POST', 'orders', json = order) + if r.ok: # TODO: figure out the AWB and the (item, barcode, voucherId, ...) for the items - json_resp = r.json() - #print(json.dumps(json_resp, indent=4)) - _logger.info("Order Response: %s", json_resp) - # TODO: download the PDF for each AWB - return json_resp + json_resp = r.json() + #print(json.dumps(json_resp, indent=4)) + _logger.info("Order Response: %s", json_resp) + # TODO: download the PDF for each AWB + return json_resp + else: + raise ValueError('%s: %s' % (r.status_code, r.text)) def api_get_item_label(self, item_id, accept='application/pdf'): """Download the label for a given item. Returns PDF as 'bytes'""" r = self.request('GET', 'items/%s/label' % item_id, headers={'Accept': accept}) + r.raise_for_status() return r.content def api_get_item_labels(self, awb, accept='application/pdf'): """Download the labels for all items in a given AWB. Returns PDF as 'bytes'""" r = self.request('GET', 'shipments/%s/itemlabels' % awb, headers={'Accept': accept}) + r.raise_for_status() return r.content