Skip to content

Programmatically set error

Compare
Choose a tag to compare
@MZanggl MZanggl released this 13 Sep 07:47
· 4 commits to master since this release

Sometimes you may wish to set the error programmatically, unrelated to the actual promise.

import promistate from 'promistate'

const promise = promistate(() => fetch('...'))

promise.error = new Error('internal error')

or with the react hook:

import { usePromistate } from 'promistate/lib/react'

const [promise, actions] = usePromistate(() => fetch('...'))

actions.setError(new Error('internal error'))