import type { AxiosError } from 'axios'; import { config as apiServicesConfig } from '../../../config/config'; const notifyTransformer = (notificationObject) => { /* if passed arg is function, then this notification - static content, predefined before actual transformer is called in applyTransform flow */ if (typeof notificationObject === 'function') { /* so, create a callback which will send notification with params, passed to it */ const callback = ({ type, text }) => apiServicesConfig.eventBus?.$emit('notification', { type, text, }); /* and, then, return a function, which will be called in main applyTransform flow, calling passed arg function with callback, and returning actual notify payload */ return (payload) => { notificationObject({ callback, }); return payload; }; } if (notificationObject instanceof Error) { const { response } = notificationObject as AxiosError<{ translation?: string; detail?: string; message?: string; }>; const errorText = response?.data?.translation || response?.data?.detail || response?.data?.message || notificationObject; apiServicesConfig.eventBus?.$emit('notification', { type: 'error', text: errorText, }); } return notificationObject; }; export default notifyTransformer;