Skip to content

Commit

Permalink
Merge pull request #54 from MarcioMeier/feat/return-success-on-delete…
Browse files Browse the repository at this point in the history
…-wso2

feat: return success on 404 error when deleting api
  • Loading branch information
flaviostutz authored Jan 21, 2025
2 parents 32c0488 + 392dcef commit bb348d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lib/src/wso2/wso2-api/handler/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
7 changes: 6 additions & 1 deletion lib/src/wso2/wso2-api/handler/wso2-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
});
};

/**
Expand Down

0 comments on commit bb348d3

Please sign in to comment.