From 9d90090eb368eacc4d95b1c023854198736a8321 Mon Sep 17 00:00:00 2001 From: BarreiroT Date: Tue, 29 Sep 2026 13:55:53 -0300 Subject: [PATCH] Prevent throwing an error when succesfully whitelisting someone --- src/radar/radar.spec.ts | 14 +++++++++++++- src/radar/radar.ts | 9 +++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/radar/radar.spec.ts b/src/radar/radar.spec.ts index d166c85c8..b2cce7032 100644 --- a/src/radar/radar.spec.ts +++ b/src/radar/radar.spec.ts @@ -86,7 +86,19 @@ describe('Radar', () => { expect(fetchBody()).toEqual( expect.objectContaining({ entry: 'test_entry' }), ); - expect(result.message).toBe('Entry already present in list'); + expect(result?.message).toBe('Entry already present in list'); + }); + + it('returns null when the entry is added successfully', async () => { + fetchOnce(undefined, { status: 204, headers: { 'content-type': '' } }); + + const result = await workos.radar.addListEntry({ + type: 'ip_address', + action: 'block', + entry: 'test_entry', + }); + + expect(result).toBeNull(); }); }); diff --git a/src/radar/radar.ts b/src/radar/radar.ts index 3020bee89..a9e976112 100644 --- a/src/radar/radar.ts +++ b/src/radar/radar.ts @@ -93,12 +93,12 @@ export class Radar { * @example "block" * @param options.entry - The value to add to the list. Must match the format of the list type (e.g. a valid IP address for `ip_address`, a valid email for `email`). * @example "198.51.100.42" - * @returns {Promise} + * @returns {Promise} * @throws {BadRequestException} 400 */ async addListEntry( options: AddListEntryOptions, - ): Promise { + ): Promise { const { type, action, ...payload } = options; const { data } = await this.workos.post< RadarListEntryAlreadyPresentResponseWire, @@ -107,6 +107,11 @@ export class Radar { `/radar/lists/${encodeURIComponent(type)}/${encodeURIComponent(action)}`, serializeRadarStandaloneUpdateRadarListRequest(payload), ); + if (!data) { + // Adding an entry successfully returns 204 No Content, + // so we can't deserialize the response. + return null; + } return deserializeRadarListEntryAlreadyPresentResponse(data); }