Skip to content

Commit ccc9f30

Browse files
committed
update logger error message for hashAttributes and hashSha256
1 parent 4dfbc71 commit ccc9f30

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/roktManager.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ export default class RoktManager {
294294
return hashedAttributes;
295295

296296
} catch (error) {
297-
return Promise.reject(error instanceof Error ? error : new Error('Failed to hash attributes'));
297+
const errorMessage = error instanceof Error ? error.message : String(error);
298+
this.logger.error(`Failed to hash "${attributes}", selectPlacements will continue: ${errorMessage}`);
299+
return {};
298300
}
299301
}
300302

@@ -342,7 +344,7 @@ export default class RoktManager {
342344
return await this.sha256Hex(normalizedValue);
343345
} catch (error) {
344346
const errorMessage = error instanceof Error ? error.message : String(error);
345-
this.logger.error(`Failed to hash "${attribute}" and returning undefined, selectPlacements will continue: ${errorMessage}`);
347+
this.logger.error(`Failed to hash "${attribute}" and returning undefined: ${errorMessage}`);
346348
return undefined;
347349
}
348350
}

test/jest/roktManager.spec.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,20 @@ describe('RoktManager', () => {
145145
expect(result).toEqual({});
146146
});
147147

148-
it('should reject if hashSha256 throws an error', async () => {
148+
it('should log error if hashSha256 throws an error', async () => {
149149
shaSpy.mockRestore();
150150

151151
// Mock hashSha256 to throw an error
152152
const hashError = new Error('Hashing failed');
153153
jest.spyOn(roktManager, 'hashSha256').mockRejectedValue(hashError);
154154

155155
const attributes = { email: '[email protected]' };
156+
const result = await roktManager.hashAttributes(attributes);
156157

157-
await expect(roktManager.hashAttributes(attributes))
158-
.rejects
159-
.toThrow('Hashing failed');
158+
expect(result).toEqual({});
159+
expect(mockMPInstance.Logger.error).toHaveBeenCalledWith(
160+
expect.stringContaining('Failed to hash "')
161+
);
160162
});
161163
});
162164

@@ -222,7 +224,7 @@ describe('RoktManager', () => {
222224

223225
expect(result).toBeUndefined();
224226
expect(mockMPInstance.Logger.error).toHaveBeenCalledWith(
225-
expect.stringContaining('Failed to hash "[email protected]" and returning undefined, selectPlacements will continue')
227+
expect.stringContaining('Failed to hash "[email protected]" and returning undefined')
226228
);
227229
});
228230

0 commit comments

Comments
 (0)