Skip to content

Commit 210b312

Browse files
log and prevent failure creating release
1 parent 0c4c11c commit 210b312

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

api/src/shared/infrastructure/lcms.js

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ const createRelease = async function () {
3535
url: lcmsConfig.url + '/releases',
3636
headers: { Authorization: `Bearer ${lcmsConfig.apiKey}` },
3737
});
38+
39+
if (!response.isSuccessful) {
40+
logger.error(`An error occurred while creating a release on ${lcmsConfig.url}: ${JSON.stringify(response)}`);
41+
throw new Error(`An error occurred while creating a release on ${lcmsConfig.url}`);
42+
}
43+
3844
return response.data.content;
3945
};
4046

api/tests/shared/unit/infrastructure/lcms_test.js

+14
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,19 @@ describe('Unit | Infrastructure | LCMS', function () {
7777
// then
7878
expect(response).to.deep.equal(learningContent);
7979
});
80+
81+
it('throws when LCMS Api response is not successful', async function () {
82+
// given
83+
nock('https://lcms-test.pix.fr/api')
84+
.post('/releases')
85+
.matchHeader('Authorization', 'Bearer test-api-key')
86+
.reply(403);
87+
88+
// when
89+
const error = await catchErr(lcms.createRelease)();
90+
91+
// then
92+
expect(error.message).to.deep.equal('An error occurred while creating a release on https://lcms-test.pix.fr/api');
93+
});
8094
});
8195
});

0 commit comments

Comments
 (0)