解决:未设置 custom.catch: true,会返回一个永远 pending 的 Promise

This commit is contained in:
WindowBird 2025-11-17 09:22:06 +08:00
parent 37f9b0b6e8
commit 9c7b0a2373
3 changed files with 7 additions and 8 deletions

View File

@ -106,7 +106,8 @@ export const applyTaskDelay = (payload) => {
export const createTask = (payload) => { export const createTask = (payload) => {
return uni.$uv.http.post('/bst/task', payload, { return uni.$uv.http.post('/bst/task', payload, {
custom: { custom: {
auth: true auth: true,
catch: true // 允许在 catch 中处理错误
} }
}); });
}; };

View File

@ -862,7 +862,8 @@ const handleSubmit = async () => {
}); });
try { try {
await createTask(payload); const res = await createTask(payload);
console.log('@@@@@@@@@@',res);
uni.hideLoading(); uni.hideLoading();
uni.showToast({ uni.showToast({
title: '创建成功', title: '创建成功',
@ -874,14 +875,11 @@ const handleSubmit = async () => {
}, 1200); }, 1200);
} catch (error) { } catch (error) {
uni.hideLoading(); uni.hideLoading();
submitting.value = false;
console.error('创建任务失败:', error); console.error('创建任务失败:', error);
uni.showToast({ //
title: error.message || '创建失败,请重试',
icon: 'none'
});
} finally { } finally {
submitting.value = false; submitting.value = false;
console.log('submitting', submitting.value);
} }
}; };

View File

@ -10,7 +10,7 @@ export const Request = () => {
// 初始化请求配置 // 初始化请求配置
uni.$uv.http.setConfig((config) => { uni.$uv.http.setConfig((config) => {
/* config 为默认全局配置*/ /* config 为默认全局配置*/
config.baseURL = 'http://192.168.1.5:4001'; /* 根域名 */ config.baseURL = 'http://192.168.1.9:4001'; /* 根域名 */
// config.baseURL = 'https://pm.ccttiot.com/prod-api'; /* 根域名 */ // config.baseURL = 'https://pm.ccttiot.com/prod-api'; /* 根域名 */
return config return config
}) })