Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
web-et-numerique
LLLE_Project
Ecolyo
Commits
df755292
Commit
df755292
authored
May 09, 2022
by
Guilhem CARRON
Browse files
fix(init): Prevent backoffice issue to make the app crash
parent
c523f78a
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/services/partnersInfo.service.spec.ts
View file @
df755292
...
...
@@ -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
()
=>
{
...
...
src/services/partnersInfo.service.ts
View file @
df755292
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
}
`
)
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment