如何调试传奇?

use*_*776 7 redux-saga

我该如何调试这个问题?我找不到要关注的信息。

我有以下传奇:

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);
}
Run Code Online (Sandbox Code Playgroud)

try 块会引发错误。将error在catch块是不确定的。

控制台显示 uncaught at at at at b TypeError: Cannot read property 'result' of undefined

单步执行代码让我浏览了一堆我不理解的库代码。

The*_*One 0

如果此传奇正在浏览器中执行,您可以debugger像平常一样使用 来暂停执行并检查变量。如果它在服务器上,console.log就可以正常工作。

就错误而言,最佳实践是redux-saga call在传奇中生成已执行函数时始终使用该方法。因此,您应该将其更改为:

    yield call(client.mutate, options)
Run Code Online (Sandbox Code Playgroud)