Skip to content

Commit a78419e

Browse files
committed
return undefined instead of throwing when hashSha256 fails
1 parent 1098eee commit a78419e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/roktManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ export default class RoktManager {
308308
return await this.sha256Hex(normalizedValue);
309309
} catch (error) {
310310
const errorMessage = error instanceof Error ? error.message : String(error);
311-
this.logger.error('Failed to hash attribute: ' + errorMessage);
312-
throw error;
311+
this.logger.error(`Failed to hash "${attribute}" and returning undefined, selectPlacements will continue: ${errorMessage}`);
312+
return undefined;
313313
}
314314
}
315315

test/jest/roktManager.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,15 @@ describe('RoktManager', () => {
269269
expect(mockMPInstance.Logger.warning).toHaveBeenCalledWith('hashSha256 received undefined as input');
270270
});
271271

272-
it('should log error when hashing fails', async () => {
272+
it('should return undefined and log error when hashing fails', async () => {
273273
shaSpy.mockRejectedValue(new Error('Hash failed'));
274274

275-
await expect(roktManager.hashSha256('[email protected]')).rejects.toThrow();
276-
expect(mockMPInstance.Logger.error).toHaveBeenCalledWith(expect.stringContaining('Failed to hash attribute'));
275+
const result = await roktManager.hashSha256('[email protected]');
276+
277+
expect(result).toBeUndefined();
278+
expect(mockMPInstance.Logger.error).toHaveBeenCalledWith(
279+
expect.stringContaining('Failed to hash "[email protected]" and returning undefined, selectPlacements will continue')
280+
);
277281
});
278282

279283
it('should hash firstName to known SHA-256 value', async () => {

0 commit comments

Comments
 (0)