diff --git a/.vscode/settings.json b/.vscode/settings.json index 0f2b73db4b0c9297e6efbf7ea113751822a70800..e40cc9102c40e9a08df4a403abc8be3be016abe4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -28,21 +28,30 @@ ], "cSpell.words": [ "acces", + "adresse", "apikey", + "appartement", "arret", "Arret", + "autorisation", "backoffice", "catched", "cicid", + "collecte", + "contractuelles", + "contrat", "Corrigees", + "courbe", "cozyclient", "criteres", + "demande", "Derniere", "Detaillees", "ecolyo", "enedis", "Enedis", "enedissgegrandlyon", + "escalier", "Etage", "etat", "faultstring", @@ -50,19 +59,31 @@ "Generales", "grandlyon", "HISTO", + "initiateur", "insee", "konnector", "konnectors", "lastname", + "Libelle", "llle", "maxpower", + "mesure", + "mesures", "numerique", "numero", "Perimetre", "periodicite", + "personne", "PMAX", + "rechercher", "Recurrente", "resultat", - "soapenv" + "soapenv", + "sociale", + "souscrit", + "souscrits", + "soutirage", + "utilisateur", + "voie" ] } diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e1266c290a5c6255770a542fbfa913b5c208e9c..67e727018920a0c4734b1846cd7e92a6781724fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [1.3.5](https://forge.grandlyon.com/web-et-numerique/llle_project/enedis-sge-konnector/compare/v1.3.4...v1.3.5) (2023-11-29) + + +### Features + +* consent ID is now a string ([2042c7c](https://forge.grandlyon.com/web-et-numerique/llle_project/enedis-sge-konnector/commit/2042c7cf4599d04b0b91706878c9b768c1d452ae)) + + +### Bug Fixes + +* removed contract start date limitation ([dc98258](https://forge.grandlyon.com/web-et-numerique/llle_project/enedis-sge-konnector/commit/dc9825848253dc5a36f2489f449c0b7870f9f43c)) + ### [1.3.4](https://forge.grandlyon.com/web-et-numerique/llle_project/enedis-sge-konnector/compare/v1.3.3...v1.3.4) (2023-10-02) diff --git a/__tests__/core/contractStartDate.spec.js b/__tests__/core/contractStartDate.spec.js deleted file mode 100644 index 1831c7d754e905207f77a91132bac850cd8057a9..0000000000000000000000000000000000000000 --- a/__tests__/core/contractStartDate.spec.js +++ /dev/null @@ -1,90 +0,0 @@ -const { errors } = require('cozy-konnector-libs') -const { getContractStartDate } = require('../../src/core/contractStartDate') -const xml2js = require('xml2js') - -const mockSoapRequest = jest.fn() -jest.mock('easy-soap-request', () => async () => mockSoapRequest()) - -const responseMock = { - response: { - body: `<?xml version="1.0" encoding="UTF-8"?> -<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> - <soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> - <ns7:consulterDonneesTechniquesContractuellesResponse xmlns:ns0="http://www.erdf.fr/tube/exposition/finalisation" xmlns:ns7="http://www.enedis.fr/sge/b2b/services/consulterdonneestechniquescontractuelles/v1.0"> - <point id="19160781274487"> - <donneesGenerales> - <dateDerniereModificationFormuleTarifaireAcheminement>2021-08-01+02:00</dateDerniereModificationFormuleTarifaireAcheminement> - <niveauOuvertureServices>2</niveauOuvertureServices> - </donneesGenerales> - </point> - </ns7:consulterDonneesTechniquesContractuellesResponse> - </soap:Body> -</soapenv:Envelope>`, - }, -} - -const responseIssueMock = { - response: { - body: `<?xml version="1.0" encoding="UTF-8"?> -<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> - <soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> - <ns7:consulterDonneesTechniquesContractuellesResponse xmlns:ns0="http://www.erdf.fr/tube/exposition/finalisation" xmlns:ns7="http://www.enedis.fr/sge/b2b/services/consulterdonneestechniquescontractuelles/v1.0"> - <point id="19160781274487"> - </point> - </ns7:consulterDonneesTechniquesContractuellesResponse> - </soap:Body> -</soapenv:Envelope>`, - }, -} - -describe('getContractStartDate', () => { - it('should return void when successfully got contract start date ✅', async () => { - mockSoapRequest.mockResolvedValueOnce(responseMock) - expect.assertions(1) - try { - await getContractStartDate( - 'http://pouet.com', - 'apiAuthKey', - 'pouet@pouet.com', - '1111111111' - ) - expect(true).toBeTruthy() - } catch (error) { - expect(true).toBe(false) - } - }) - - it('should throw VENDOR_DOWN when failing request 🚫', async () => { - mockSoapRequest.mockRejectedValueOnce('error') - - try { - await getContractStartDate() - expect(true).toBe(false) - } catch (error) { - expect(error.message).toBe(errors.VENDOR_DOWN) - } - }) - - it('should throw NOT_EXISTING_DIRECTORY when failing parsing 🚫', async () => { - mockSoapRequest.mockResolvedValueOnce(responseIssueMock) - jest.spyOn(xml2js, 'parseStringPromise').mockResolvedValueOnce({ - Envelope: { - Body: { - Fault: { detail: { erreur: { resultat: { $: { code: 401 } } } } }, - faultstring: 'Mock error', - }, - }, - }) - try { - await getContractStartDate( - 'http://pouet.com', - 'apiAuthKey', - 'pouet@pouet.com', - '1111111111' - ) - expect(true).toBe(false) - } catch (error) { - expect(error.message).toBe(errors.NOT_EXISTING_DIRECTORY) - } - }) -}) diff --git a/__tests__/helpers/parsing.spec.js b/__tests__/helpers/parsing.spec.js index c6fcc9758cde13b50a7290fc62487bd06bd50d08..b45b2def934d7d32658a39c263453d236e7a03e5 100644 --- a/__tests__/helpers/parsing.spec.js +++ b/__tests__/helpers/parsing.spec.js @@ -1,6 +1,5 @@ const { parseUserPdl, - parseContractStartDate, parseContracts, parseServiceId, parseSgeXmlData, @@ -27,24 +26,6 @@ describe('parsing', () => { const reply = parseUserPdl(result) expect(reply).toEqual(1) }) - it('should parse contract start date', () => { - const result = { - Envelope: { - Body: { - consulterDonneesTechniquesContractuellesResponse: { - point: { - donneesGenerales: { - dateDerniereModificationFormuleTarifaireAcheminement: - '01/01/2022', - }, - }, - }, - }, - }, - } - const reply = parseContractStartDate(result) - expect(reply).toEqual('01/01/2022') - }) it('should parse contract', () => { const result = { Envelope: { diff --git a/__tests__/requests/bo.spec.js b/__tests__/requests/bo.spec.js index ea0dca564ea26d8e3b0f9e7bbad12400492cc8e2..fb95043b7b4efac7959c13c3d97fa87de57dcc78 100644 --- a/__tests__/requests/bo.spec.js +++ b/__tests__/requests/bo.spec.js @@ -11,18 +11,16 @@ jest.mock('axios') describe('Backoffice routes', () => { describe('createBoConsent', () => { it('should send consent to BO', async () => { - axios.post.mockImplementationOnce(() => { - return { - data: { - ID: 1, - firstname: 'mr', - lastname: 'POUET', - pointId: 11111111111111, - postalCode: '69003', - address: '20 rue du lac', - inseeCode: '69383', - }, - } + axios.post.mockResolvedValueOnce({ + data: { + ID: 1, + firstname: 'mr', + lastname: 'POUET', + pointId: 11111111111111, + postalCode: '69003', + address: '20 rue du lac', + inseeCode: '69383', + }, }) const consent = await createBoConsent( 'http://test.com', @@ -45,7 +43,7 @@ describe('Backoffice routes', () => { }) }) it('should handle unavailable BO', async () => { - axios.post.mockImplementationOnce(() => Promise.reject('fail')) + axios.post.mockRejectedValueOnce(new Error('request failed')) try { await createBoConsent( 'http://test.com', @@ -65,19 +63,17 @@ describe('Backoffice routes', () => { }) describe('updateBoConsent', () => { it('should update consent to BO', async () => { - axios.put.mockImplementationOnce(() => { - return { - data: { - ID: 1, - firstname: 'mr', - lastname: 'POUET', - pointId: 11111111111111, - postalCode: '69003', - address: '20 rue du lac', - inseeCode: '69383', - serviceId: '123456', - }, - } + axios.put.mockResolvedValueOnce({ + data: { + ID: 1, + firstname: 'mr', + lastname: 'POUET', + pointId: 11111111111111, + postalCode: '69003', + address: '20 rue du lac', + inseeCode: '69383', + serviceId: '123456', + }, }) const consent = await updateBoConsent( 'http://test.com', @@ -105,7 +101,7 @@ describe('Backoffice routes', () => { }) }) it('should handle unavailable BO', async () => { - axios.put.mockImplementationOnce(() => Promise.reject('fail')) + axios.put.mockRejectedValueOnce(new Error('request failed')) try { await updateBoConsent( 'http://test.com', @@ -130,19 +126,17 @@ describe('Backoffice routes', () => { describe('deleteBoConsent', () => { it('should delete consent to BO', async () => { - axios.delete.mockImplementationOnce(() => { - return { - data: { - ID: 1, - firstname: 'mr', - lastname: 'POUET', - pointId: 11111111111111, - postalCode: '69003', - address: '20 rue du lac', - inseeCode: '69383', - serviceId: '123456', - }, - } + axios.delete.mockResolvedValueOnce({ + data: { + ID: 1, + firstname: 'mr', + lastname: 'POUET', + pointId: 11111111111111, + postalCode: '69003', + address: '20 rue du lac', + inseeCode: '69383', + serviceId: '123456', + }, }) const consent = await deleteBoConsent('http://test.com', 'token', 1) expect(consent).toEqual({ @@ -157,7 +151,7 @@ describe('Backoffice routes', () => { }) }) it('should handle unavailable BO', async () => { - axios.put.mockImplementationOnce(() => Promise.reject('fail')) + axios.put.mockRejectedValueOnce(new Error('request failed')) try { await deleteBoConsent('http://test.com', 'token', 1) expect(true).toBe(false) @@ -168,17 +162,15 @@ describe('Backoffice routes', () => { }) describe('getBoConsent', () => { it('should get consent from BO', async () => { - axios.get.mockImplementationOnce(() => { - return { - data: { - ID: 1, - pointId: 11111111111111, - name: 'POUET', - adresse: '20 rue du lac', - postalCode: '69003', - inseeCode: '69383', - }, - } + axios.get.mockResolvedValueOnce({ + data: { + ID: 1, + pointId: 11111111111111, + name: 'POUET', + adresse: '20 rue du lac', + postalCode: '69003', + inseeCode: '69383', + }, }) const consent = await getBoConsent('http://test.com', 'token', 1) expect(consent).toEqual({ @@ -192,19 +184,28 @@ describe('Backoffice routes', () => { }) it('should handle unavailable BO', async () => { - axios.get.mockImplementationOnce(() => Promise.reject(errors.MAINTENANCE)) + axios.get.mockRejectedValueOnce(new Error('request failed')) try { - await getBoConsent({ - pointId: 11111111111111, - name: 'POUET', - adresse: '20 rue du lac', - postalCode: '69003', - inseeCode: '69383', - }) + await getBoConsent('http://test.com', 'token', '1') expect(true).toBe(false) } catch (error) { expect(error.message).toBe(errors.MAINTENANCE) } }) + + it('should handle not found consent', async () => { + axios.get.mockRejectedValueOnce({ + response: { + status: 404, + data: { description: 'Not Found' }, + }, + }) + try { + await getBoConsent('http://test.com', 'token', 'n0tF0unD') + expect(true).toBe(false) + } catch (error) { + expect(error.message).toBe(errors.LOGIN_FAILED) + } + }) }) }) diff --git a/manifest.konnector b/manifest.konnector index 7037c7b2b6b372336bf6957a610199f0311dc45e..e9252c654f180b72a315a78e934a16cf8b38fa00 100644 --- a/manifest.konnector +++ b/manifest.konnector @@ -1,5 +1,5 @@ { - "version": "1.3.4", + "version": "1.3.5", "name": "Enedis SGE", "type": "konnector", "language": "node", diff --git a/package.json b/package.json index 0ca07dc96e77f7fad2d42038c60a67d9c2e213c9..5fa1c0561bccfb1b29a42707afdde3c154697faf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "enedissgegrandlyon", - "version": "1.3.4", + "version": "1.3.5", "description": "", "repository": { "type": "https", diff --git a/src/core/contractStartDate.js b/src/core/contractStartDate.js deleted file mode 100644 index 10e5e3afaac53eea2265c86e83a73b5837e1eba9..0000000000000000000000000000000000000000 --- a/src/core/contractStartDate.js +++ /dev/null @@ -1,67 +0,0 @@ -// @ts-check -const { log, errors } = require('cozy-konnector-libs') -const soapRequest = require('easy-soap-request') -const { - parseTags, - parseValue, - parseContractStartDate, -} = require('../helpers/parsing') -const xml2js = require('xml2js') -const { consulterDonneesTechniquesContractuelles } = require('../requests/sge') -const Sentry = require('@sentry/node') - -/** - * Get user contract start date - * @param {string} url - * @param {string} apiAuthKey - * @param {string} userLogin - * @param {string} pointId - * @returns {Promise<string>} - */ -async function getContractStartDate(url, apiAuthKey, userLogin, pointId) { - log('info', 'Fetching data start date') - const sgeHeaders = { - 'Content-Type': 'text/xml;charset=UTF-8', - apikey: apiAuthKey, - } - - const { response } = await soapRequest({ - url: `${url}/enedis_SGE_ConsultationDonneesTechniquesContractuelles/1.0`, - headers: sgeHeaders, - xml: consulterDonneesTechniquesContractuelles(pointId, userLogin), - }).catch(err => { - const errorMessage = - 'Error while fetching contract start date : ' + err.message - log('error', errorMessage) - Sentry.captureException(errorMessage, { - tags: { - section: 'getContractStartDate', - }, - extra: { - pointId: pointId, - }, - }) - throw new Error(errors.VENDOR_DOWN) - }) - - const result = await xml2js.parseStringPromise(response.body, { - tagNameProcessors: [parseTags], - valueProcessors: [parseValue], - explicitArray: false, - }) - try { - return parseContractStartDate(result) - } catch (error) { - const errorMessage = - 'Error while processing contract start date: ' + error.message - log('error', errorMessage) - Sentry.captureException(errorMessage) - log( - 'error', - `Enedis issue ${result.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${result.Envelope.Body.Fault.faultstring}` - ) - throw new Error(errors.NOT_EXISTING_DIRECTORY) - } -} - -module.exports = { getContractStartDate } diff --git a/src/core/index.js b/src/core/index.js index 70e2d7ee4c550722f40a6442b3f2ecf942870cd1..e71b1625a6a9a95ff091256225f0ab54cce64ecf 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,5 +1,4 @@ const { activateContract } = require('./contractActivation') -const { getContractStartDate } = require('./contractStartDate') const { terminateContract } = require('./contractTermination') const { verifyContract } = require('./contractVerification') const { findUserPdl } = require('./findUserPdl') @@ -8,7 +7,6 @@ const { findUserAddress } = require('./findUserAddress') module.exports = { activateContract, - getContractStartDate, terminateContract, verifyContract, findUserPdl, diff --git a/src/core/types/types.js b/src/core/types/types.js index 5a344f9061d4f856717f0df7e037aabfbdb3d401..0fea863b6ac3926c7211130e754a4cc038b49905 100644 --- a/src/core/types/types.js +++ b/src/core/types/types.js @@ -40,7 +40,7 @@ * @property {string} inseeCode * @property {string} endDate * @property {number} [serviceID] - * @property {number} [ID] + * @property {string} [ID] */ /** @@ -53,7 +53,7 @@ * @property {string} address * @property {string} inseeCode * @property {string} city - * @property {boolean} hasBeenThroughtSafetyOnBoarding + * @property {boolean} hasBeenThroughSafetyOnBoarding */ /** @@ -87,7 +87,7 @@ /** * AccountData definition * @typedef {object} AccountData - * @property {number} consentId + * @property {string} consentId * @property {string} inseeCode */ diff --git a/src/core/verifyUserIdentity.js b/src/core/verifyUserIdentity.js index 3ee35cf94546a6fe9c8961c097e041af294377db..a7376fd11d77f29e60011425efa6c76a22cc9953 100644 --- a/src/core/verifyUserIdentity.js +++ b/src/core/verifyUserIdentity.js @@ -153,7 +153,7 @@ async function verifyUserIdentity( inseeCode, postalCode: fields.postalCode, address: fields.address, - hasBeenThroughtSafetyOnBoarding: userSafetyOnBoarding, + hasBeenThroughSafetyOnBoarding: userSafetyOnBoarding, city: fields.city, } } diff --git a/src/helpers/parsing.js b/src/helpers/parsing.js index c947599840f4907bc40b5e1f21940ea1c6e051f2..862f2256078f06429357e27b141d3c076a65a7ac 100644 --- a/src/helpers/parsing.js +++ b/src/helpers/parsing.js @@ -16,20 +16,6 @@ function parseUserPdl(result) { ]['point']['$'].id } -/** - * Return User contract start date - * @param {string} result - * @returns {string} - */ -function parseContractStartDate(result) { - log('info', 'Parsing contract start date') - const json = JSON.stringify(result) - return JSON.parse(json)['Envelope']['Body'][ - 'consulterDonneesTechniquesContractuellesResponse' - ]['point']['donneesGenerales'][ - 'dateDerniereModificationFormuleTarifaireAcheminement' - ] -} /** * Return User address * @param {string} result @@ -88,7 +74,7 @@ function parseSgeXmlData(result) { * @returns {Promise<EnedisKonnectorData[]>} Parsed timestamp array */ async function formateDataForDoctype(data) { - log('info', 'Formating data') + log('info', 'Formatting data') return data.map(record => { const date = moment(record.d, 'YYYY/MM/DD h:mm:ss') return { @@ -228,7 +214,6 @@ module.exports = { checkContractExists, formateDataForDoctype, parseContracts, - parseContractStartDate, parsePointId, parseServiceId, parseSgeXmlData, diff --git a/src/index.js b/src/index.js index 77d9a6686dbb17df2c5c1264eea7871b37d0589e..6dc43d8928168e9e1a7a090c91cb438cd2524516 100644 --- a/src/index.js +++ b/src/index.js @@ -34,7 +34,6 @@ const { activateContract, verifyContract, terminateContract, - getContractStartDate, } = require('./core') const { getAccount, saveAccountData } = require('./requests/cozy') const { isLocal, isDev } = require('./helpers/env') @@ -47,13 +46,12 @@ moment.locale('fr') // set the language moment.tz.setDefault('Europe/Paris') // set the timezone /** Connector Constants **/ -const manualExecution = - process.env.COZY_JOB_MANUAL_EXECUTION === 'true' ? true : false -let startDailyDate = manualExecution +const manualExecution = process.env.COZY_JOB_MANUAL_EXECUTION === 'true' +let startDate = manualExecution ? moment().subtract(12, 'month') - : moment().subtract(6, 'month') -let startDailyDateString = startDailyDate.format('YYYY-MM-DD') -const startLoadDate = moment().subtract(7, 'day') + : moment().subtract(36, 'month') +let startDateString = startDate.format('YYYY-MM-DD') +const startHalfHourDate = moment().subtract(7, 'day') const endDate = moment() const endDateString = endDate.format('YYYY-MM-DD') const ACCOUNT_ID = isLocal() ? 'default_account_id' : 'enedissgegrandlyon' @@ -172,20 +170,9 @@ async function start(fields, cozyParameters) { user.postalCode, user.inseeCode, user.city, - user.hasBeenThroughtSafetyOnBoarding + user.hasBeenThroughSafetyOnBoarding ) - // handle user contract start date in order to properly request data - const userContractStartDate = await getContractStartDate( - baseUrl, - apiAuthKey, - sgeLogin, - pointId - ) - - startDailyDate = moment(userContractStartDate, 'YYYY-MM-DD') - startDailyDateString = startDailyDate.format('YYYY-MM-DD') - const contractStartDate = moment().format('YYYY-MM-DD') const contractEndDate = moment() .add(1, 'year') // SGE force 1 year duration @@ -357,16 +344,6 @@ async function deleteConsent( */ async function gatherData(baseUrl, apiAuthKey, sgeLogin, pointId) { log('info', 'Querying data...') - const userContractStartDate = await getContractStartDate( - baseUrl, - apiAuthKey, - sgeLogin, - pointId - ) - - startDailyDate = moment(userContractStartDate, 'YYYY-MM-DD') - startDailyDateString = startDailyDate.format('YYYY-MM-DD') - await getData( `${baseUrl}/enedis_SGE_ConsultationMesuresDetaillees_v3/1.0`, apiAuthKey, @@ -402,15 +379,13 @@ async function getData(url, apiAuthKey, userLogin, pointId) { apikey: apiAuthKey, } - limitStartDate() - const { response } = await soapRequest({ url: url, headers: sgeHeaders, xml: consultationMesuresDetaillees( pointId, userLogin, - startDailyDateString, + startDateString, endDateString, 'ENERGIE', 'EA' @@ -449,15 +424,13 @@ async function getMaxPowerData(url, apiAuthKey, userLogin, pointId) { apikey: apiAuthKey, } - limitStartDate() - const { response } = await soapRequest({ url: url, headers: sgeHeaders, xml: consultationMesuresDetailleesMaxPower( pointId, userLogin, - startDailyDateString, + startDateString, endDateString ), }).catch(err => { @@ -480,27 +453,6 @@ async function getMaxPowerData(url, apiAuthKey, userLogin, pointId) { ) } -/** - * If start date exceed the maximum amount of data we can get with one query - * get only 36 month. Or 12 month if manual execution - * On manual execution, set the start date to one year ago. - */ -function limitStartDate() { - const livingDuration = moment(endDate).diff(startDailyDate, 'months', true) - // We need to prevent case that there is less than 12 month data - if (manualExecution && livingDuration > 12) { - startDailyDate = moment(endDate).subtract(12, 'month') - startDailyDateString = startDailyDate.format('YYYY-MM-DD') - } else if (livingDuration > 36) { - log( - 'info', - 'Start date exceed 36 month, setting start date to current date minus 36 month' - ) - startDailyDate = moment(endDate).subtract(36, 'month') - startDailyDateString = startDailyDate.format('YYYY-MM-DD') - } -} - /** * Get half-hour data * @param {string} url @@ -520,7 +472,7 @@ async function getDataHalfHour(url, apiAuthKey, userLogin, pointId) { for (let i = 0; i < MAX_HISTO; i++) { log('info', 'launch process with history') - const incrementedStartDateString = moment(startLoadDate) + const incrementedStartDateString = moment(startHalfHourDate) .subtract(7 * i, 'day') .format('YYYY-MM-DD') const incrementedEndDateString = moment(endDate) @@ -657,7 +609,7 @@ async function aggregateMonthAndYearData(data) { * @returns {boolean} */ function isFirstStart(account) { - if (account && account.data && account.data.consentId) { + if (account?.data?.consentId) { log('info', 'Konnector not first start') return false } diff --git a/src/requests/bo.js b/src/requests/bo.js index 8addf82e97d319c58719333856aa9bd57a9586b7..9be6341e9e5902dc86609f55c8b343535569280b 100644 --- a/src/requests/bo.js +++ b/src/requests/bo.js @@ -82,7 +82,7 @@ async function updateBoConsent(url, token, consent, serviceId) { let consentId = '' if (consent.ID) { - consentId = consent.ID.toString() + consentId = consent.ID } try { const { data } = await axios.put( @@ -110,7 +110,7 @@ async function updateBoConsent(url, token, consent, serviceId) { } /** - * @param {number} consentId + * @param {string} consentId * @returns {Promise<Consent>} */ async function getBoConsent(url, token, consentId) { @@ -134,6 +134,9 @@ async function getBoConsent(url, token, consentId) { consentId: consentId, }, }) + if (err.response?.status === 404) { + throw new Error(errors.LOGIN_FAILED) + } throw new Error(errors.MAINTENANCE) } } @@ -142,7 +145,7 @@ async function getBoConsent(url, token, consentId) { * Delete BO consent * @param {string} url * @param {string} token - * @param {number} consentId + * @param {string} consentId * @returns */ async function deleteBoConsent(url, token, consentId) { diff --git a/src/requests/cozy.js b/src/requests/cozy.js index 71bc1f76dd819846af47b2a97a6858eb2a930dc1..2e22ceba07e45a2b0d553abd7caa95736f23d65b 100644 --- a/src/requests/cozy.js +++ b/src/requests/cozy.js @@ -39,6 +39,7 @@ async function saveAccountData(accountId, accountData) { async function getAccount(accountId) { log('info', `getAccount: ${accountId}`) const accounts = await cozyClient.data.findAll('io.cozy.accounts') + log('info', `getAccount data: ${JSON.stringify(accounts)}`) return accounts.filter(account => isLocal() ? account._id === accountId : account.account_type === accountId )[0]