Skip to content

Commit 48347c5

Browse files
fix invalid identifiers error code (#424)
1 parent a2dba60 commit 48347c5

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

Diff for: optimizely/helpers/enums.py

-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ class Errors:
120120
NONE_VARIABLE_KEY_PARAMETER: Final = '"None" is an invalid value for variable key.'
121121
UNSUPPORTED_DATAFILE_VERSION: Final = (
122122
'This version of the Python SDK does not support the given datafile version: "{}".')
123-
INVALID_SEGMENT_IDENTIFIER: Final = 'Audience segments fetch failed (invalid identifier).'
124123
FETCH_SEGMENTS_FAILED: Final = 'Audience segments fetch failed ({}).'
125124
ODP_EVENT_FAILED: Final = 'ODP event send failed ({}).'
126125
ODP_NOT_INTEGRATED: Final = 'ODP is not integrated.'

Diff for: optimizely/odp/odp_segment_api_manager.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,15 @@ def fetch_segments(self, api_key: str, api_host: str, user_key: str,
172172

173173
if response_dict and 'errors' in response_dict:
174174
try:
175-
error_class = response_dict['errors'][0]['extensions']['classification']
176-
except (KeyError, IndexError):
175+
extensions = response_dict['errors'][0]['extensions']
176+
error_class = extensions['classification']
177+
error_code = extensions.get('code')
178+
except (KeyError, IndexError, TypeError):
177179
self.logger.error(Errors.FETCH_SEGMENTS_FAILED.format('decode error'))
178180
return None
179181

180-
if error_class == 'InvalidIdentifierException':
181-
self.logger.warning(Errors.INVALID_SEGMENT_IDENTIFIER)
182+
if error_code == 'INVALID_IDENTIFIER_EXCEPTION':
183+
self.logger.warning(Errors.FETCH_SEGMENTS_FAILED.format('invalid identifier'))
182184
return None
183185
else:
184186
self.logger.error(Errors.FETCH_SEGMENTS_FAILED.format(error_class))
@@ -188,6 +190,6 @@ def fetch_segments(self, api_key: str, api_host: str, user_key: str,
188190
audiences = response_dict['data']['customer']['audiences']['edges']
189191
segments = [edge['node']['name'] for edge in audiences if edge['node']['state'] == 'qualified']
190192
return segments
191-
except KeyError:
193+
except (KeyError, TypeError):
192194
self.logger.error(Errors.FETCH_SEGMENTS_FAILED.format('decode error'))
193195
return None

Diff for: tests/test_odp_segment_api_manager.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ def test_fetch_qualified_segments__500(self):
344344
"customer"
345345
],
346346
"extensions": {
347-
"classification": "InvalidIdentifierException"
347+
"classification": "DataFetchingException",
348+
"code": "INVALID_IDENTIFIER_EXCEPTION"
348349
}
349350
}
350351
],

0 commit comments

Comments
 (0)