Как мне отладить сагу? - PullRequest
       5

Как мне отладить сагу?

0 голосов
/ 04 сентября 2018

Как я могу отладить эту проблему? Я не могу найти информацию для подражания.

У меня есть следующая сага:

export function* generateSoftwareLicenseCode({distributor, licenseType, duration}: GenerateSoftwareLicenseCodeAction) {
    const username = getUsername();
    const jwtToken = yield call(getJwtToken, username);

    const link = new HttpLink({
        uri: getGraphqlEndpointUrl,
        headers: {
            'x-api-key': getApiKey(),
            'Authorization': jwtToken,
        },
    });
    const client = new ApolloClient({
        link: link,
        cache: new InMemoryCache(),
    });

    try {
        yield put(setStatusMessage('Generating license code...', 'info'));

        yield client.mutate({
            /* tslint:disable */
            mutation: gql`
                }
                mutation licensemutation($distributor: String!, licenceType: String!, duration: String, userId: String) {
                    addLicenseCodeOneTimeUsage(distributor: $distributor, licenseType: $licenseType, duration: $duration, userId: $userId) {
                        code
                    }
                }
            `,
            /* tslint:enable */
            variables: {
                userId: username,
                distributor: distributor,
                licenseType: licenseType,
                duration: duration,
            },
        });
        const doneMessage = 'License code successfully generated';
        yield put(generateSoftwareLicenseCodeSucceeded(doneMessage));
    } catch (error) {
        const errors = error.networkError.result.errors;
        yield put(generateSoftwareLicenseCodeFailed(filterErrorMessage(errors)));
    }
}

export function* softwareLicenseCodesSagas() {
    const generateSoftwareLicenseCodeWatcher = yield takeLatest(GENERATE_SOFTWARE_LICENSE_CODE_ACTION, generateSoftwareLicenseCode);
    yield take(LOCATION_CHANGE);
    yield put(clearMessages());
    yield cancel(generateSoftwareLicenseCodeWatcher);
}

Блок try выдает ошибку. error в блоке catch не определено.

Консоль показывает uncaught at at at at b TypeError: Cannot read property 'result' of undefined

Пройдя по коду, я получаю кучу библиотечного кода, который я не понимаю.

1 Ответ

0 голосов
/ 04 сентября 2018

Если эта сага выполняется в браузере, вы можете использовать debugger, чтобы приостановить выполнение и проверить переменные, как обычно. Если он находится на сервере, console.log будет работать нормально.

С точки зрения ошибки, рекомендуется всегда использовать метод redux-saga call при получении исполняемых функций в саге. Поэтому вы должны изменить его на:

yield call(client.mutate, options)
...