import { createEvent, createStore, type Effect } from 'effector'

export function createErrorStore(fx: Effect<any, any, any>) {
  const reset = createEvent()
  const $error = createStore<unknown | null>(null)
    .on(fx.failData, (_, e) => e)
    .reset([fx, reset])

  return { $error, reset }
}
