Skip to content

Commit

Permalink
[TECH] Logger et prévenir le crash de container lorsque la création d…
Browse files Browse the repository at this point in the history
…e release est en échec

 #10483
  • Loading branch information
pix-service-auto-merge authored Nov 5, 2024
2 parents 0c4c11c + 210b312 commit 054a5a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/src/shared/infrastructure/lcms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
14 changes: 14 additions & 0 deletions api/tests/shared/unit/infrastructure/lcms_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});

0 comments on commit 054a5a3

Please sign in to comment.