Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions packages/uni-api/src/helpers/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export const scopedInterceptors: { [key: string]: Interceptors } = {}

function wrapperHook(hook: Function, params?: Record<string, any>) {
return function (data: unknown) {
return hook(data, params) || data
const result = hook(data, params);
// 只有当结果为undefined或null时才返回data,保留false值
return result === undefined || result === null ? data : result;
Comment on lines +25 to +27
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic change from || data to explicit undefined/null checking is significant and may affect other use cases. Consider adding unit tests to verify this doesn't break existing functionality where hooks return other falsy values like 0 or empty string.

Copilot uses AI. Check for mistakes.

}
}

Expand All @@ -35,12 +37,33 @@ function queue(
for (let i = 0; i < hooks.length; i++) {
const hook = hooks[i]
if (promise) {
promise = Promise.resolve(wrapperHook(hook, params))
const wrappedHook = wrapperHook(hook, params);
promise = promise.then((data) => {
const res = wrappedHook(data);
if (isPromise(res)) {
return res.then((res) => {
if (res === false) {
return { then() {}, catch() {} } as Promise<undefined>;
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock Promise object with empty then() and catch() methods may cause issues with Promise chaining. Consider using Promise.reject() or a proper rejected Promise to maintain consistent Promise behavior.

Copilot uses AI. Check for mistakes.

}
return res;
});
}
if (res === false) {
return { then() {}, catch() {} } as Promise<undefined>;
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock Promise object with empty then() and catch() methods may cause issues with Promise chaining. Consider using Promise.reject() or a proper rejected Promise to maintain consistent Promise behavior.

Copilot uses AI. Check for mistakes.

}
return res;
});
} else {
const res = hook(data, params)
if (isPromise(res)) {
promise = Promise.resolve(res)
}
// 修改这里:处理异步返回 false 的情况
promise = res.then((res) => {
if (res === false) {
return { then() {}, catch() {} } as Promise<undefined>;
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock Promise object with empty then() and catch() methods may cause issues with Promise chaining. Consider using Promise.reject() or a proper rejected Promise to maintain consistent Promise behavior.

Copilot uses AI. Check for mistakes.

}
return res;
});
}
if (res === false) {
return {
then() {},
Expand Down
Loading