import SeamlyGeneralError from 'api/errors/seamly-general-error' import { setInterrupt } from 'domains/interrupt/slice' const handledErrorTypes = [ 'SeamlyGeneralError', 'SeamlyConfigurationError', 'SeamlySessionExpiredError', 'SeamlyOfflineError', 'SeamlyUnauthorizedError', 'SeamlyUnavailableError', ] export default function createInterruptMiddleware({ api }) { return () => (next) => (action) => { const { payload, type } = action if (type === setInterrupt.type) { if (!handledErrorTypes.includes(payload.name)) { throw new SeamlyGeneralError(payload) } else if (payload.action === 'reset') { // [SMLY-942] We clear the store before a reset to force a new conversation if the page is refreshed before the conversation is reset api.disconnect().then(() => { api.clearStore() }) } } return next(action) } }