Commit df755292 authored by Guilhem CARRON's avatar Guilhem CARRON
Browse files

fix(init): Prevent backoffice issue to make the app crash

parent c523f78a
......@@ -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 () => {
......
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}`)
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment