gpt4 book ai didi

redux-saga - 如何调试传奇?

转载 作者:行者123 更新时间:2023-12-01 17:00:40 25 4
gpt4 key购买 nike

如何调试这个问题?我找不到可追踪的信息。

我有以下传奇故事:

    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 block 抛出错误。 catch block 中的错误未定义。

控制台显示uncaught at at at b TypeError:无法读取未定义的属性“结果”

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

最佳答案

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

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

    yield call(client.mutate, options)

关于redux-saga - 如何调试传奇?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52168129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com