def _raise_if_error(decoded_response): raise_error = False # Catch a manifest/chunk error if any(key in decoded_response for key in ['error', 'errordata']): raise_error = True # Catch a license error if 'result' in decoded_response and isinstance(decoded_response.get('result'), list): if 'error' in decoded_response['result'][0]: raise_error = True if raise_error: common.error('Full MSL error information:') common.error(json.dumps(decoded_response)) raise MSLError(_get_error_details(decoded_response)) return decoded_response
def _process_json_response(response): """Execute a post request and expect a JSON response""" try: return _raise_if_error(response.json()) except ValueError: raise MSLError('Expected JSON response, got {}'.format(response.text))