G
G
GaserV2019-02-22 16:13:38
React
GaserV, 2019-02-22 16:13:38

Why does undefined fall in a catch block in a saga?

Such a problem. Throws an error when testing:

TypeError: Cannot read property 'message' of undefined
. Why undefined? In theory, everything seems to be so.
Saga:
export function* updateUser({ payload }) {
    try {
        const response = yield call(api.updateUser, payload);
        yield put(updateUserSuccess(response));
    } catch (e) {
        yield put(updateUserFailure(e.data.message)); //на эту строку ошибка падает
        yield put(req.showError(e.data.message));
    }
}

Test(Jest):
const gen = sagas.updateUser({ payload: 'test' });
            const error = {data: {message: 'error'}}

            gen.next();

            expect(gen.throw(error).value).toMatchSnapshot();

            expect(gen.next().value).toMatchSnapshot();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GaserV, 2019-02-25
@GaserV

It is not clear why, but renaming "error" to "e" everything worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question