From 210b31248d9aec582707592678c90bf5740c7822 Mon Sep 17 00:00:00 2001 From: Laura Bergoens Date: Tue, 5 Nov 2024 14:09:59 +0100 Subject: [PATCH] log and prevent failure creating release --- api/src/shared/infrastructure/lcms.js | 6 ++++++ api/tests/shared/unit/infrastructure/lcms_test.js | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/api/src/shared/infrastructure/lcms.js b/api/src/shared/infrastructure/lcms.js index cce7a0a7b81..09cd074a30a 100644 --- a/api/src/shared/infrastructure/lcms.js +++ b/api/src/shared/infrastructure/lcms.js @@ -35,6 +35,12 @@ const createRelease = async function () { url: lcmsConfig.url + '/releases', headers: { Authorization: `Bearer ${lcmsConfig.apiKey}` }, }); + + if (!response.isSuccessful) { + logger.error(`An error occurred while creating a release on ${lcmsConfig.url}: ${JSON.stringify(response)}`); + throw new Error(`An error occurred while creating a release on ${lcmsConfig.url}`); + } + return response.data.content; }; diff --git a/api/tests/shared/unit/infrastructure/lcms_test.js b/api/tests/shared/unit/infrastructure/lcms_test.js index cd23f8106f6..53737f043c0 100644 --- a/api/tests/shared/unit/infrastructure/lcms_test.js +++ b/api/tests/shared/unit/infrastructure/lcms_test.js @@ -77,5 +77,19 @@ describe('Unit | Infrastructure | LCMS', function () { // then expect(response).to.deep.equal(learningContent); }); + + it('throws when LCMS Api response is not successful', async function () { + // given + nock('https://lcms-test.pix.fr/api') + .post('/releases') + .matchHeader('Authorization', 'Bearer test-api-key') + .reply(403); + + // when + const error = await catchErr(lcms.createRelease)(); + + // then + expect(error.message).to.deep.equal('An error occurred while creating a release on https://lcms-test.pix.fr/api'); + }); }); });