diff --git a/src/core/contractVerification.js b/src/core/contractVerification.js index abc62f013b4ea520e4cd92b80f1fc0cf6a2c435e..6df8b9c45cd697fa211106ba002a4347212d4091 100644 --- a/src/core/contractVerification.js +++ b/src/core/contractVerification.js @@ -37,6 +37,11 @@ async function verifyContract(url, apiAuthKey, appLogin, contractId, pointId) { }) try { + if (!checkContractExists(parsedReply)) { + log('error', 'no contract found') + return null + } + const currentContracts = parseContracts(parsedReply) let currentContract = null if (Array.isArray(currentContracts)) { @@ -61,4 +66,15 @@ async function verifyContract(url, apiAuthKey, appLogin, contractId, pointId) { } } +/** + * @param {string} parsedReply + * @return {boolean} + */ +function checkContractExists(parsedReply) { + const json = JSON.stringify(parsedReply) + return JSON.parse(json)['Envelope']['Body'][ + 'rechercherServicesSouscritsMesuresResponse' + ]['servicesSouscritsMesures'] +} + module.exports = { verifyContract }