Skip to content

Commit 1470f03

Browse files
doublefacedoubleface
doubleface
authored andcommittedDec 20, 2021
feat: Use configured support address in UNKNOWN_ERROR message
This will display the expected support mail in the message according to the context. I had to convert the TriggerErrorInfo to a Component class since it now needs asynchronous information from io.cozy.settings.

File tree

6 files changed

+76
-16
lines changed

6 files changed

+76
-16
lines changed
 

‎packages/cozy-harvest-lib/src/components/AccountForm/__snapshots__/index.spec.jsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ exports[`AccountForm should render error 1`] = `
8080
onFocusCapture={[Function]}
8181
onKeyUp={[Function]}
8282
>
83-
<withI18n(withKonnectorLocales(TriggerErrorInfo)
83+
<withI18n(withClient(withKonnectorLocales(TriggerErrorInfo))
8484
className="u-mb-1"
8585
error={[Error: Test error]}
8686
konnector={

‎packages/cozy-harvest-lib/src/components/infos/TriggerErrorInfo.jsx

+28-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import PropTypes from 'prop-types'
44
import { translate } from 'cozy-ui/transpiled/react/I18n'
55
import Infos from 'cozy-ui/transpiled/react/Infos'
66
import Typography from 'cozy-ui/transpiled/react/Typography'
7+
import { withClient } from 'cozy-client'
78

8-
import { getErrorLocale } from '../../helpers/konnectors'
9+
import { getErrorLocale, fetchSupportMail } from '../../helpers/konnectors'
910
import withKonnectorLocales from '../hoc/withKonnectorLocales'
1011
import Markdown from '../Markdown'
1112

@@ -18,8 +19,20 @@ import Markdown from '../Markdown'
1819
* deals mainly with translation concerns.
1920
*/
2021
export class TriggerErrorInfo extends PureComponent {
22+
state = {
23+
supportMail: null
24+
}
25+
async componentDidMount() {
26+
await this.loadSupportMail()
27+
}
28+
async loadSupportMail() {
29+
const { client } = this.props
30+
const supportMail = await fetchSupportMail(client)
31+
this.setState({ supportMail })
32+
}
2133
render() {
2234
const { className, error, konnector, t, action } = this.props
35+
const { supportMail } = this.state
2336
return (
2437
<Infos
2538
className={className}
@@ -30,11 +43,19 @@ export class TriggerErrorInfo extends PureComponent {
3043
<Typography className="u-error" variant="h6" gutterBottom>
3144
{getErrorLocale(error, konnector, t, 'title')}
3245
</Typography>
33-
<Typography variant="body1" component="div">
34-
<Markdown
35-
source={getErrorLocale(error, konnector, t, 'description')}
36-
/>
37-
</Typography>
46+
{supportMail ? (
47+
<Typography variant="body1" component="div">
48+
<Markdown
49+
source={getErrorLocale(
50+
error,
51+
konnector,
52+
t,
53+
'description',
54+
supportMail
55+
)}
56+
/>
57+
</Typography>
58+
) : null}
3859
</>
3960
}
4061
/>
@@ -48,4 +69,4 @@ TriggerErrorInfo.proptTypes = {
4869
t: PropTypes.func.isRequired
4970
}
5071

51-
export default translate()(withKonnectorLocales(TriggerErrorInfo))
72+
export default translate()(withClient(withKonnectorLocales(TriggerErrorInfo)))

‎packages/cozy-harvest-lib/src/components/infos/TriggerErrorInfo.spec.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const fixtures = {
1616
const tMock = jest.fn().mockImplementation(key => key)
1717

1818
describe('TriggerErrorInfo', () => {
19+
let fakeClient
1920
beforeAll(() => {
2021
jest.spyOn(console, 'error').mockImplementation(() => {})
2122
})
@@ -31,7 +32,9 @@ describe('TriggerErrorInfo', () => {
3132
}
3233

3334
const setup = ({ props: optionProps } = {}) => {
34-
const fakeClient = {}
35+
fakeClient = {
36+
query: jest.fn()
37+
}
3538
const root = render(
3639
<AppLike client={fakeClient}>
3740
<TriggerErrorInfo {...props} {...optionProps} />
@@ -53,4 +56,16 @@ describe('TriggerErrorInfo', () => {
5356
})
5457
expect(root.findByText('An unknown error has occurred.')).toBeTruthy()
5558
})
59+
60+
it('should render unknown error with configured mail support if any', () => {
61+
fakeClient.query.mockResolvedValue({
62+
data: { attributes: { support_address: 'test@address' } }
63+
})
64+
const { root } = setup({
65+
props: {
66+
error: new Error('Something is undefined')
67+
}
68+
})
69+
expect(root.findByText('test@address')).toBeTruthy()
70+
})
5671
})

‎packages/cozy-harvest-lib/src/helpers/konnectors.js

+29-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import has from 'lodash/has'
33
import trim from 'lodash/trim'
44
import { getBoundT } from '../locales'
55

6+
import { Q } from 'cozy-client'
7+
68
import * as accounts from './accounts'
79

10+
const DEFAULT_SUPPORT_MAIL = 'claude@cozycloud.cc'
11+
812
// Default name for base directory
913
const DEFAULT_LOCALIZED_BASE_DIR = 'Administrative'
1014

@@ -130,11 +134,18 @@ export class KonnectorJobError extends Error {
130134
* @param {Func} suffixKey What part of the error message should be returned, title or description
131135
* @return {String} The error locale
132136
*/
133-
export const getErrorLocale = (error, konnector, t, suffixKey) => {
137+
export const getErrorLocale = (
138+
error,
139+
konnector,
140+
t,
141+
suffixKey,
142+
supportMail = DEFAULT_SUPPORT_MAIL
143+
) => {
134144
const defaultKey = 'error.job.UNKNOWN_ERROR'
135145
const translationVariables = {
136146
name: konnector.name || '',
137-
link: konnector.vendor_link || ''
147+
link: konnector.vendor_link || '',
148+
supportMail
138149
}
139150

140151
// not handled errors
@@ -156,9 +167,20 @@ export const getErrorLocale = (error, konnector, t, suffixKey) => {
156167
})
157168
}
158169

159-
export const getErrorLocaleBound = (error, konnector, lang, suffixKey) => {
170+
export const fetchSupportMail = async client => {
171+
const result = await client.query(Q('io.cozy.settings').getById('context'))
172+
return get(result, 'data.attributes.support_address', DEFAULT_SUPPORT_MAIL)
173+
}
174+
175+
export const getErrorLocaleBound = (
176+
error,
177+
konnector,
178+
lang,
179+
suffixKey,
180+
supportMail
181+
) => {
160182
const t = getBoundT(lang)
161-
return getErrorLocale(error, konnector, t, suffixKey)
183+
return getErrorLocale(error, konnector, t, suffixKey, supportMail)
162184
}
163185

164186
/**
@@ -364,5 +386,7 @@ export default {
364386
getLauncher,
365387
isRunnable,
366388
hasNewVersionAvailable,
367-
needsFolder
389+
needsFolder,
390+
fetchSupportMail,
391+
DEFAULT_SUPPORT_MAIL
368392
}

‎packages/cozy-harvest-lib/src/locales/en.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
},
156156
"UNKNOWN_ERROR": {
157157
"title": "Connection error",
158-
"description": "An unknown error has occurred. You can try to update your data. If the problem persists, please contact us at [claude@cozycloud.cc](mailto:claude@cozycloud.cc)."
158+
"description": "An unknown error has occurred. You can try to update your data. If the problem persists, please contact us at [%{supportMail}](mailto:%{supportMail})."
159159
},
160160
"USER_ACTION_NEEDED": {
161161
"title": "Action needed on the provider's website",

‎packages/cozy-harvest-lib/src/locales/fr.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
},
156156
"UNKNOWN_ERROR": {
157157
"title": "Erreur de Connexion",
158-
"description": "Une erreur inconnue est survenue. Vous pouvez essayer de mettre à jour vos données. Si le problème persiste, n'hésitez pas à nous contacter via [claude@cozycloud.cc](mailto:claude@cozycloud.cc)."
158+
"description": "Une erreur inconnue est survenue. Vous pouvez essayer de mettre à jour vos données. Si le problème persiste, n'hésitez pas à nous contacter via [%{supportMail}](mailto:%{supportMail})."
159159
},
160160
"USER_ACTION_NEEDED": {
161161
"title": "Action nécessaire chez le fournisseur",

0 commit comments

Comments
 (0)
Please sign in to comment.