From 392dcef014f8dff5fcbc15bc6f34e50121347dc9 Mon Sep 17 00:00:00 2001 From: Marcio Meier Date: Tue, 21 Jan 2025 11:22:43 +0100 Subject: [PATCH] feat: return success on 404 error when deleting api --- lib/src/wso2/wso2-api/handler/index.test.ts | 19 +++++++++++++++++++ lib/src/wso2/wso2-api/handler/wso2-v1.ts | 7 ++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/src/wso2/wso2-api/handler/index.test.ts b/lib/src/wso2/wso2-api/handler/index.test.ts index e00c2a0..e3270b1 100644 --- a/lib/src/wso2/wso2-api/handler/index.test.ts +++ b/lib/src/wso2/wso2-api/handler/index.test.ts @@ -381,6 +381,25 @@ describe('wso2 custom resource lambda', () => { expect(eres.Status).toBe('SUCCESS'); }); + it('should return success when api does not exists on DELETE operation', async () => { + nockBasicWso2SDK(); + + // api update mock + nock(baseWso2Url) + .delete(/.*\/publisher\/v1\/apis\/.*$/) + .reply(404); + + const eres = await handler( + testCFNEventDelete( + { + ...testEvent, + }, + '123-456', + ), + ); + expect(eres.Status).toBe('SUCCESS'); + }); + const toResultList = (apiDefs: PublisherPortalAPIv1): { list: ApiFromListV1[] } => { return { list: [ diff --git a/lib/src/wso2/wso2-api/handler/wso2-v1.ts b/lib/src/wso2/wso2-api/handler/wso2-v1.ts index b5af323..5535d03 100644 --- a/lib/src/wso2/wso2-api/handler/wso2-v1.ts +++ b/lib/src/wso2/wso2-api/handler/wso2-v1.ts @@ -93,7 +93,12 @@ export const removeApiInWso2 = async (args: { if (!args.wso2ApiId) { throw new Error('wso2ApiId is required for deleting API'); } - await args.wso2Axios.delete(`/api/am/publisher/v1/apis/${args.wso2ApiId}`); + await args.wso2Axios.delete(`/api/am/publisher/v1/apis/${args.wso2ApiId}`, { + validateStatus(status) { + // If it returns 404, the api is already deleted + return status === 200 || status === 404; + }, + }); }; /**