aboutsummaryrefslogtreecommitdiff
path: root/src/site/plugins/handler.js
blob: 7933eab09f54ccc0b6af7efe4431b917e92aeef5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import AlertTypes from '~/constants/alertTypes';

export default ({ store }, inject) => {
	inject('handler', {
		async executeAction(action, param) {
			try {
				const response = await store.dispatch(action, param);

				store.commit('alert/set', {
					message: response?.message ?? 'Executed sucesfully',
					type: AlertTypes.SUCCESS
				});

				return response;
			} catch (e) {
				store.commit('alert/set', {
					message: e.message,
					type: AlertTypes.ERROR
				});

				return null;
			}
		}
	});
};