From 306b2a11a59d47e161c36a9e976428f6e0519edc Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 16 Aug 2013 20:39:24 +0200 Subject: tracking: Say that no packages were found if the Posten API returns HTTP 404. --- modules/tracking.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/tracking.py b/modules/tracking.py index 478ae9d..3fd6638 100644 --- a/modules/tracking.py +++ b/modules/tracking.py @@ -110,6 +110,10 @@ class PostenModule(TrackingModule): def get_xml(self, url): try: u = urllib2.urlopen(url, timeout = config.getfloat(cfg_section, 'timeout')) + except urllib2.HTTPError as e: + if e.code == 404: + raise NoPackageFound('No packages found') + raise PackageError(str(e)) except Exception as e: raise PackageError(str(e)) if u.headers['content-type'].startswith('application/xml'): @@ -331,6 +335,9 @@ class Module: for row in consignments: try: self.track_update(row.code, propagate_error = True) + except NoPackageFound: + results.append('No packages found for %s' % unicode(row)) + continue except PackageError as e: results.append('Failed to fetch data for %s.' % unicode(row)) continue -- cgit v1.2.3