Wrap `createFlash` arguments in a object and add support for sentry
Purpose
Implementation of RFC gitlab-org/frontend/rfcs#63 (closed)
We currently use createFlash
pretty extensively through the codebase to display feedback to a user after some kind of action, including reporting errors. We have now also introduced Sentry js and are starting to make use of Sentry.captureException
to capture errors.
Solution
- Rename
createFlash
tooldCreateFlash
and update all imports toimport { oldCreateFlash as createFlash } from '~/flash'
- Add the new
createFlash
to the codebase, taking an object - Each
js
andvue
file that uses the currentcreateFlash
should be updated to use the new create flash function:
- Update import:
// Before
import { oldCreateFlash as createFlash } from '~/flash'
// After
import createFlash from '~/flash'
- Update the ordered arguments, with their named equivalents
// Before
...
.catch(error => {
createFlash('Error message to display', 'warning');
});
// After
.catch(error => {
createFlash({ message: 'Error message to display', type: 'warning' });
});
- For cases where we also capture the error in sentry, we should add the new
captureError: true
anderror
arguments
// Before
...
.catch(e => {
Sentry.captureException(e);
createFlash(s__('OnDemandScans|Could not run the scan. Please try again.'));
});
// After
...
.catch(e => {
createFlash({
message: s__('OnDemandScans|Could not run the scan. Please try again.'),
captureError: true,
error: e
});
});
- Remove the old
createFlash
method
- Show closed items
Link items together to show that they're related or that one is blocking others.