From 7f28e2672201f601904433253da0fa5024514978 Mon Sep 17 00:00:00 2001 From: kdsudac Date: Wed, 29 Jan 2020 13:27:54 -0800 Subject: [PATCH] Better error handling and display of error message Correctly classifying 400 errors as InvalidTestRunError's so they are not re-tried. Better support and display of the new message field being returned by backend. --- openhtf/output/callbacks/mfg_inspector.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/openhtf/output/callbacks/mfg_inspector.py b/openhtf/output/callbacks/mfg_inspector.py index dbe79c76c..15db16a67 100644 --- a/openhtf/output/callbacks/mfg_inspector.py +++ b/openhtf/output/callbacks/mfg_inspector.py @@ -43,11 +43,15 @@ def _send_mfg_inspector_request(envelope_data, credentials, destination_url): logging.warning('Upload failed with response %s: %s', resp, content) raise UploadFailedError(resp, content) - if resp.status != 200: - logging.warning('Upload failed: %s', result) - raise UploadFailedError(result['error'], result) - - return result + if resp.status == 200: + return result + + message = '%s: %s' % (result.get('error', + 'UNKNOWN_ERROR'), result.get('message')) + if resp.status == 400: + raise InvalidTestRunError(message) + else: + raise UploadFailedError(message) def send_mfg_inspector_data(inspector_proto, credentials, destination_url):