Skip to content
Snippets Groups Projects
Commit da28f531 authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

fix: prevent unavailable backoffice to crash the app

parent 08f669d7
Branches
Tags
2 merge requests!777Update master to V2.0,!743fix: prevent unavailable backoffice to crash the app
...@@ -15,7 +15,6 @@ export enum InitStepsErrors { ...@@ -15,7 +15,6 @@ export enum InitStepsErrors {
ECOGESTURE_ERROR = 'ecogesture_error', ECOGESTURE_ERROR = 'ecogesture_error',
CHALLENGES_ERROR = 'challenges_error', CHALLENGES_ERROR = 'challenges_error',
ANALYSIS_ERROR = 'analysis_error', ANALYSIS_ERROR = 'analysis_error',
PRICES_ERROR = 'prices_error',
CONSOS_ERROR = 'consos_error', CONSOS_ERROR = 'consos_error',
PARTNERS_ERROR = 'partners_error', PARTNERS_ERROR = 'partners_error',
NETWORK_ERROR = 'network_error', NETWORK_ERROR = 'network_error',
......
...@@ -21,11 +21,12 @@ describe('PartnersInfo service', () => { ...@@ -21,11 +21,12 @@ describe('PartnersInfo service', () => {
it('should return an error', async () => { it('should return an error', async () => {
mockClient.getStackClient().fetchJSON.mockRejectedValue(new Error()) mockClient.getStackClient().fetchJSON.mockRejectedValue(new Error())
let res
try { try {
await customPupopService.getCustomPopup() res = await customPupopService.getCustomPopup()
expect(true).toBe(false) expect(true).toBe(false)
} catch (error) { } catch (error) {
expect(error).toEqual(new Error('Error while getting customPopup')) expect(res).toBe(undefined)
} }
}) })
}) })
import { Client } from 'cozy-client' import { Client } from 'cozy-client'
import { CustomPopup } from 'models/customPopup.model' import { CustomPopup } from 'models/customPopup.model'
import EnvironmentService from './environment.service' import EnvironmentService from './environment.service'
import logger from 'cozy-logger'
const log = logger.namespace('customPupopService')
export default class CustomPupopService { export default class CustomPupopService {
private readonly _client: Client private readonly _client: Client
constructor(_client: Client) { constructor(_client: Client) {
...@@ -24,8 +25,10 @@ export default class CustomPupopService { ...@@ -24,8 +25,10 @@ export default class CustomPupopService {
.fetchJSON('GET', remoteUrl) .fetchJSON('GET', remoteUrl)
return result as CustomPopup return result as CustomPopup
} catch (error) { } catch (error) {
console.error(`getCustomPopup: Failed to get custom popup:${error}`) log(
throw new Error('Error while getting customPopup') 'error',
`getCustomPopup: Failed to get custom popup:${JSON.stringify(error)}`
)
} }
} }
} }
import { Client, Q, QueryDefinition } from 'cozy-client' import { Client } from 'cozy-client'
import challengeEntityData from 'db/challengeEntity.json' import challengeEntityData from 'db/challengeEntity.json'
import duelEntityData from 'db/duelEntity.json' import duelEntityData from 'db/duelEntity.json'
import ecogestureData from 'db/ecogestureData.json' import ecogestureData from 'db/ecogestureData.json'
...@@ -43,7 +43,8 @@ import FluidPricesService from './fluidsPrices.service' ...@@ -43,7 +43,8 @@ import FluidPricesService from './fluidsPrices.service'
import ProfileEcogestureService from './profileEcogesture.service' import ProfileEcogestureService from './profileEcogesture.service'
import ProfileTypeEntityService from './profileTypeEntity.service' import ProfileTypeEntityService from './profileTypeEntity.service'
import TermsService from './terms.service' import TermsService from './terms.service'
import logger from 'cozy-logger'
const cozyLog = logger.namespace('initializationService')
export default class InitializationService { export default class InitializationService {
private readonly _client: Client private readonly _client: Client
private readonly _setinitStep: React.Dispatch<React.SetStateAction<InitSteps>> private readonly _setinitStep: React.Dispatch<React.SetStateAction<InitSteps>>
...@@ -240,9 +241,8 @@ export default class InitializationService { ...@@ -240,9 +241,8 @@ export default class InitializationService {
log.info('[Initialization] FluidPrices db created successfully') log.info('[Initialization] FluidPrices db created successfully')
return true return true
} catch (err) { } catch (err) {
this._setinitStepError(InitStepsErrors.PRICES_ERROR)
log.error('Initialization error - initFluidPrices: ', err) log.error('Initialization error - initFluidPrices: ', err)
cozyLog('error', `Initialization error - initFluidPrices: ${err}`)
return false return false
} }
} }
......
...@@ -32,11 +32,12 @@ describe('PartnersInfo service', () => { ...@@ -32,11 +32,12 @@ describe('PartnersInfo service', () => {
it('should return an error', async () => { it('should return an error', async () => {
mockClient.getStackClient().fetchJSON.mockRejectedValue(new Error()) mockClient.getStackClient().fetchJSON.mockRejectedValue(new Error())
let res
try { try {
await partnersInfoService.getPartnersInfo() res = await partnersInfoService.getPartnersInfo()
expect(true).toBe(false) expect(true).toBe(false)
} catch (error) { } catch (error) {
expect(error).toEqual(new Error('Error while getting partnersInfo')) expect(res).toBe(undefined)
} }
}) })
}) })
import { Client } from 'cozy-client' import { Client } from 'cozy-client'
import { PartnersInfo } from 'models/partnersInfo.model' import { PartnersInfo } from 'models/partnersInfo.model'
import EnvironmentService from './environment.service' import EnvironmentService from './environment.service'
import logger from 'cozy-logger'
const log = logger.namespace('partnersInfoService')
export default class PartnersInfoService { export default class PartnersInfoService {
private readonly _client: Client private readonly _client: Client
...@@ -24,8 +26,10 @@ export default class PartnersInfoService { ...@@ -24,8 +26,10 @@ export default class PartnersInfoService {
.fetchJSON('GET', remoteUrl) .fetchJSON('GET', remoteUrl)
return result as PartnersInfo return result as PartnersInfo
} catch (error) { } catch (error) {
console.error(`getPartnersInfo: Failed to get partners info:${error}`) log(
throw new Error('Error while getting partnersInfo') 'error',
`getPartnersInfo: Failed to get partners info: ${JSON.stringify(error)}`
)
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment