From df75529265787eaba84ae44d2445ed6244495f4c Mon Sep 17 00:00:00 2001 From: gcarron <gcarron@grandlyon.com> Date: Mon, 9 May 2022 16:38:26 +0200 Subject: [PATCH] fix(init): Prevent backoffice issue to make the app crash --- src/services/partnersInfo.service.spec.ts | 4 +++- src/services/partnersInfo.service.ts | 20 +++----------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/services/partnersInfo.service.spec.ts b/src/services/partnersInfo.service.spec.ts index f96b94fb4..69aaaade2 100644 --- a/src/services/partnersInfo.service.spec.ts +++ b/src/services/partnersInfo.service.spec.ts @@ -14,7 +14,9 @@ describe('PartnersInfo service', () => { const partnersInfoService = new PartnersInfoService(mockClient) it('should return partnersInfo', async () => { - const result: PartnersInfo = await partnersInfoService.getPartnersInfo() + const result: + | PartnersInfo + | undefined = await partnersInfoService.getPartnersInfo() expect(result).toEqual(undefined) }) it('should return an error', async () => { diff --git a/src/services/partnersInfo.service.ts b/src/services/partnersInfo.service.ts index 6cde2383b..52d464263 100644 --- a/src/services/partnersInfo.service.ts +++ b/src/services/partnersInfo.service.ts @@ -1,22 +1,11 @@ import { Client } from 'cozy-client' -import { InitStepsErrors } from 'models/initialisationSteps.model' import { PartnersInfo } from 'models/partnersInfo.model' import EnvironmentService from './environment.service' export default class PartnersInfoService { private readonly _client: Client - private readonly _setinitStepError?: React.Dispatch< - React.SetStateAction<InitStepsErrors | null> - > - - constructor( - _client: Client, - _setinitStepError?: React.Dispatch< - React.SetStateAction<InitStepsErrors | null> - > - ) { + constructor(_client: Client) { this._client = _client - this._setinitStepError = _setinitStepError } /* @@ -24,7 +13,7 @@ export default class PartnersInfoService { * On success, respond the partnersInfo * Else, throw an error */ - public async getPartnersInfo(): Promise<PartnersInfo> { + public async getPartnersInfo(): Promise<PartnersInfo | undefined> { const env = new EnvironmentService() const remoteUrl = env.isProduction() ? `/remote/org.ecolyo.backoffice.partners.info` @@ -35,10 +24,7 @@ export default class PartnersInfoService { .fetchJSON('GET', remoteUrl) return result as PartnersInfo } catch (error) { - this._setinitStepError && - this._setinitStepError(InitStepsErrors.PARTNERS_ERROR) - console.error(error) - throw new Error("Failed to get partners' info") + console.error(`getPartnersInfo: Failed to get partners info:${error}`) } } } -- GitLab