Skip to content

Commit 43cb6ea

Browse files
authored
[FSSDK-9126] fix(ats): handle INVALID_IDENTIFIER_EXCEPTION error (#821)
1 parent 2580ea0 commit 43cb6ea

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

packages/optimizely-sdk/lib/core/odp/odp_segment_api_manager.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,13 @@ export class OdpSegmentApiManager implements IOdpSegmentApiManager {
108108
}
109109

110110
if (parsedSegments.errors?.length > 0) {
111-
const errors = parsedSegments.errors.map(e => e.message).join('; ');
111+
const { code, classification } = parsedSegments.errors[0].extensions;
112112

113-
this.logger.log(LogLevel.ERROR, `${AUDIENCE_FETCH_FAILURE_MESSAGE} (${errors})`);
113+
if (code == "INVALID_IDENTIFIER_EXCEPTION") {
114+
this.logger.log(LogLevel.ERROR, `${AUDIENCE_FETCH_FAILURE_MESSAGE} (invalid identifier)`);
115+
} else {
116+
this.logger.log(LogLevel.ERROR, `${AUDIENCE_FETCH_FAILURE_MESSAGE} (${classification})`);
117+
}
114118

115119
return null;
116120
}

packages/optimizely-sdk/lib/core/odp/odp_types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export interface Location {
5858
* Extended error information
5959
*/
6060
export interface Extension {
61+
code: string;
6162
classification: string;
6263
}
6364

packages/optimizely-sdk/tests/odpSegmentApiManager.spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,32 @@ describe('OdpSegmentApiManager', () => {
179179
});
180180

181181
it('should handle error with invalid identifier', async () => {
182+
const INVALID_USER_ID = 'invalid-user';
183+
const errorJsonResponse =
184+
'{"errors":[{"message":' +
185+
'"Exception while fetching data (/customer) : ' +
186+
`Exception: could not resolve _fs_user_id = ${INVALID_USER_ID}",` +
187+
'"locations":[{"line":1,"column":8}],"path":["customer"],' +
188+
'"extensions":{"code": "INVALID_IDENTIFIER_EXCEPTION","classification":"DataFetchingException"}}],' +
189+
'"data":{"customer":null}}';
190+
when(mockRequestHandler.makeRequest(anything(), anything(), anything(), anything())).thenReturn(
191+
abortableRequest(200, errorJsonResponse)
192+
);
193+
const manager = managerInstance();
194+
195+
const segments = await manager.fetchSegments(
196+
API_key,
197+
GRAPHQL_ENDPOINT,
198+
USER_KEY,
199+
INVALID_USER_ID,
200+
SEGMENTS_TO_CHECK
201+
);
202+
203+
expect(segments).toBeNull();
204+
verify(mockLogger.log(LogLevel.ERROR, 'Audience segments fetch failed (invalid identifier)')).once();
205+
});
206+
207+
it('should handle other fetch error responses', async () => {
182208
const INVALID_USER_ID = 'invalid-user';
183209
const errorJsonResponse =
184210
'{"errors":[{"message":' +
@@ -201,7 +227,7 @@ describe('OdpSegmentApiManager', () => {
201227
);
202228

203229
expect(segments).toBeNull();
204-
verify(mockLogger.log(anything(), anyString())).once();
230+
verify(mockLogger.log(LogLevel.ERROR, 'Audience segments fetch failed (DataFetchingException)')).once();
205231
});
206232

207233
it('should handle unrecognized JSON responses', async () => {

0 commit comments

Comments
 (0)