奖励已经双倍奖励
This commit is contained in:
@@ -19,7 +19,7 @@ async function login(db, wxContext) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "Failed to get or create user"
|
||||
msg: "获取或创建用户失败"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -38,13 +38,13 @@ async function login(db, wxContext) {
|
||||
data_version: user.data_version,
|
||||
last_save_time: user.last_save_time || null
|
||||
},
|
||||
msg: "Login successful"
|
||||
msg: "登录成功"
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Login error:", error);
|
||||
console.error("登录错误:", error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Login error: ${error.message}`
|
||||
msg: `登录错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -81,13 +81,13 @@ async function getOrCreaterUser(db, openid) {
|
||||
});
|
||||
userData._id = addResult._id;
|
||||
|
||||
console.log(`New user created: ${openid}, version: ${initData.data_version}`);
|
||||
console.log(`新用户已创建: ${openid}, 版本: ${initData.data_version}`);
|
||||
} else {
|
||||
userData = res.data[0];
|
||||
|
||||
// 检查数据版本兼容性
|
||||
const versionCheck = checkDataVersionCompatibility(userData.data_version);
|
||||
console.log(`User ${openid} data version check:`, versionCheck);
|
||||
console.log(`用户 ${openid} 数据版本检查:`, versionCheck);
|
||||
|
||||
if (versionCheck.needsUpgrade) {
|
||||
// 使用新的数据管理系统合并和升级数据
|
||||
@@ -110,13 +110,13 @@ async function getOrCreaterUser(db, openid) {
|
||||
userData.equips = upgradedData.equips;
|
||||
userData.data_version = upgradedData.data_version;
|
||||
|
||||
console.log(`User ${openid} data upgraded to version: ${upgradedData.data_version}`);
|
||||
console.log(`用户 ${openid} 数据已升级到版本: ${upgradedData.data_version}`);
|
||||
}
|
||||
}
|
||||
|
||||
return userData;
|
||||
} catch (err) {
|
||||
console.error(`Get or create user err`, err);
|
||||
console.error(`获取或创建用户错误`, err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,7 @@ async function getUserInfo(db, openid) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "User not found"
|
||||
msg: "未找到用户"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -147,13 +147,13 @@ async function getUserInfo(db, openid) {
|
||||
data_version: user.data_version,
|
||||
last_save_time: user.last_save_time
|
||||
},
|
||||
msg: "User info retrieved successfully"
|
||||
msg: "用户信息获取成功"
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Get user info error:", error);
|
||||
console.error("获取用户信息错误:", error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Get user info error: ${error.message}`
|
||||
msg: `获取用户信息错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -170,7 +170,7 @@ async function checkVersion(db, openid) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "User not found"
|
||||
msg: "未找到用户"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -186,13 +186,13 @@ async function checkVersion(db, openid) {
|
||||
regist_time: user.regist_time,
|
||||
last_save_time: user.last_save_time
|
||||
},
|
||||
msg: "Version information retrieved successfully"
|
||||
msg: "版本信息获取成功"
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Check version error:", error);
|
||||
console.error("检查版本错误:", error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Check version error: ${error.message}`
|
||||
msg: `检查版本错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -253,19 +253,19 @@ async function upgradeUserData(db, openid) {
|
||||
tals: upgradedData.tals,
|
||||
equips: upgradedData.equips
|
||||
},
|
||||
msg: "Data upgrade completed successfully"
|
||||
msg: "数据升级成功完成"
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: `Upgrade fail, ${JSON.stringify(upgradeDataRes)}`
|
||||
msg: `升级失败, ${JSON.stringify(upgradeDataRes)}`
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Upgrade user data error:", error);
|
||||
console.error("升级用户数据错误:", error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Upgrade error: ${error.message}`
|
||||
msg: `升级错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,20 +15,20 @@ async function getFightHeros(db, openid) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "User not found"
|
||||
msg: "未找到用户"
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: user.fight_heros,
|
||||
msg: "Fight heros retrieved successfully"
|
||||
msg: "出战英雄获取成功"
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Get fight heros error:", error);
|
||||
console.error("获取出战英雄错误:", error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Get fight heros error: ${error.message}`
|
||||
msg: `获取出战英雄错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ async function setFightHero(db, openid, position, heroId) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "User not found"
|
||||
msg: "未找到用户"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ async function setFightHero(db, openid, position, heroId) {
|
||||
if (position < 0 || position > 4) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: "Invalid position, must be 0-4"
|
||||
msg: "无效的位置,必须是0-4"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ async function setFightHero(db, openid, position, heroId) {
|
||||
if (typeof heroId !== 'number' || heroId < 0) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: "Invalid hero ID"
|
||||
msg: "无效的英雄ID"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ async function setFightHero(db, openid, position, heroId) {
|
||||
if (heroId > 0 && !user.heros[heroId]) {
|
||||
return {
|
||||
code: -6,
|
||||
msg: "Hero not owned"
|
||||
msg: "未拥有该英雄"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -93,19 +93,19 @@ async function setFightHero(db, openid, position, heroId) {
|
||||
old_hero_id: oldHeroId,
|
||||
new_hero_id: heroId
|
||||
},
|
||||
msg: `Fight hero position ${position} updated successfully`
|
||||
msg: `出战英雄位置 ${position} 更新成功`
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: `Set fight hero fail`
|
||||
msg: `设置出战英雄失败`
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Set fight hero error:", error);
|
||||
console.error("设置出战英雄错误:", error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Set fight hero error: ${error.message}`
|
||||
msg: `设置出战英雄错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ async function updateFightHeros(db, openid, fightHeros) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "User not found"
|
||||
msg: "未找到用户"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ async function updateFightHeros(db, openid, fightHeros) {
|
||||
if (!fightHeros || typeof fightHeros !== 'object') {
|
||||
return {
|
||||
code: -3,
|
||||
msg: "Invalid fight heros data format"
|
||||
msg: "无效的出战英雄数据格式"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -144,14 +144,14 @@ async function updateFightHeros(db, openid, fightHeros) {
|
||||
if (isNaN(position) || position < 0 || position > 4) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: `Invalid position: ${pos}`
|
||||
msg: `无效的位置: ${pos}`
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof heroId !== 'number' || heroId < 0) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: `Invalid hero ID for position ${pos}: ${heroId}`
|
||||
msg: `位置 ${pos} 的英雄ID无效: ${heroId}`
|
||||
};
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ async function updateFightHeros(db, openid, fightHeros) {
|
||||
if (heroId > 0 && !user.heros[heroId]) {
|
||||
return {
|
||||
code: -6,
|
||||
msg: `Hero ${heroId} not owned for position ${pos}`
|
||||
msg: `位置 ${pos} 未拥有英雄 ${heroId}`
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -177,19 +177,19 @@ async function updateFightHeros(db, openid, fightHeros) {
|
||||
return {
|
||||
code: 200,
|
||||
data: newFightHeros,
|
||||
msg: "Fight heros updated successfully"
|
||||
msg: "出战英雄更新成功"
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: `Update fight heros fail`
|
||||
msg: `更新出战英雄失败`
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Update fight heros error:", error);
|
||||
console.error("更新出战英雄错误:", error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Update fight heros error: ${error.message}`
|
||||
msg: `更新出战英雄错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -206,7 +206,7 @@ async function getActiveFightHeros(db, openid) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "User not found"
|
||||
msg: "未找到用户"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -228,13 +228,13 @@ async function getActiveFightHeros(db, openid) {
|
||||
active_heros: activeHeros,
|
||||
total_count: activeHeros.length
|
||||
},
|
||||
msg: "Active fight heros retrieved successfully"
|
||||
msg: "获取活跃出战英雄成功"
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Get active fight heros error:", error);
|
||||
console.error("获取活跃出战英雄错误:", error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Get active fight heros error: ${error.message}`
|
||||
msg: `获取活跃出战英雄错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -254,7 +254,7 @@ async function swapFightHeros(db, openid, position1, position2) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "User not found"
|
||||
msg: "未找到用户"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -262,14 +262,14 @@ async function swapFightHeros(db, openid, position1, position2) {
|
||||
if (position1 < 0 || position1 > 4 || position2 < 0 || position2 > 4) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: "Invalid positions, must be 0-4"
|
||||
msg: "无效的位置,必须是0-4"
|
||||
};
|
||||
}
|
||||
|
||||
if (position1 === position2) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: "Cannot swap same position"
|
||||
msg: "不能交换相同位置"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -293,19 +293,19 @@ async function swapFightHeros(db, openid, position1, position2) {
|
||||
hero1_moved_to: hero1,
|
||||
hero2_moved_to: hero2
|
||||
},
|
||||
msg: `Fight heros swapped successfully`
|
||||
msg: `出战英雄交换成功`
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: `Swap fight heros fail`
|
||||
msg: `交换出战英雄失败`
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Swap fight heros error:", error);
|
||||
console.error("交换出战英雄错误:", error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Swap fight heros error: ${error.message}`
|
||||
msg: `交换出战英雄错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -324,7 +324,7 @@ async function resetFightHeros(db, openid) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "User not found"
|
||||
msg: "未找到用户"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -342,19 +342,19 @@ async function resetFightHeros(db, openid) {
|
||||
return {
|
||||
code: 200,
|
||||
data: defaultData.fight_heros,
|
||||
msg: "Fight heros reset successfully"
|
||||
msg: "出战英雄重置成功"
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: `Reset fail, ${JSON.stringify(resetRes)}`
|
||||
msg: `重置失败, ${JSON.stringify(resetRes)}`
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Reset fight heros error:", error);
|
||||
console.error("重置出战英雄错误:", error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Reset fight heros error: ${error.message}`
|
||||
msg: `重置出战英雄错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ async function getInventory(db, openid, dataType) {
|
||||
if (!validateDataType(dataType)) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: `Invalid data type: ${dataType}`
|
||||
msg: `无效的数据类型: ${dataType}`
|
||||
};
|
||||
}
|
||||
|
||||
@@ -35,20 +35,20 @@ async function getInventory(db, openid, dataType) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "User not found"
|
||||
msg: "未找到用户"
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: user[dataType],
|
||||
msg: `${dataType} retrieved successfully`
|
||||
msg: `${dataType}获取成功`
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`Get ${dataType} error:`, error);
|
||||
console.error(`获取${dataType}错误:`, error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Get ${dataType} error: ${error.message}`
|
||||
msg: `获取${dataType}错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ async function getInventoryItem(db, openid, dataType, itemId) {
|
||||
if (!validateDataType(dataType)) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: `Invalid data type: ${dataType}`
|
||||
msg: `无效的数据类型: ${dataType}`
|
||||
};
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ async function getInventoryItem(db, openid, dataType, itemId) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "User not found"
|
||||
msg: "未找到用户"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ async function getInventoryItem(db, openid, dataType, itemId) {
|
||||
if (itemCount === undefined) {
|
||||
return {
|
||||
code: -6,
|
||||
msg: `${dataType.slice(0, -1)} ${itemId} not found`
|
||||
msg: `${dataType.slice(0, -1)} ${itemId} 未找到`
|
||||
};
|
||||
}
|
||||
|
||||
@@ -92,13 +92,13 @@ async function getInventoryItem(db, openid, dataType, itemId) {
|
||||
item_id: itemId,
|
||||
count: itemCount
|
||||
},
|
||||
msg: `${dataType.slice(0, -1)} ${itemId} retrieved successfully`
|
||||
msg: `${dataType.slice(0, -1)} ${itemId} 获取成功`
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`Get ${dataType} item error:`, error);
|
||||
console.error(`获取${dataType}物品错误:`, error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Get ${dataType} item error: ${error.message}`
|
||||
msg: `获取${dataType}物品错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,7 @@ async function addInventoryItem(db, openid, dataType, itemId, count) {
|
||||
if (!validateDataType(dataType)) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: `Invalid data type: ${dataType}`
|
||||
msg: `无效的数据类型: ${dataType}`
|
||||
};
|
||||
}
|
||||
|
||||
@@ -126,14 +126,14 @@ async function addInventoryItem(db, openid, dataType, itemId, count) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "User not found"
|
||||
msg: "未找到用户"
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof count !== 'number' || count < 0) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: "Count must be a non-negative number"
|
||||
msg: "数量必须是非负数"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -156,19 +156,19 @@ async function addInventoryItem(db, openid, dataType, itemId, count) {
|
||||
new_count: newCount,
|
||||
added: count
|
||||
},
|
||||
msg: `${dataType.slice(0, -1)} ${itemId} added successfully`
|
||||
msg: `${dataType.slice(0, -1)} ${itemId} 添加成功`
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: `Add ${dataType.slice(0, -1)} fail`
|
||||
msg: `添加 ${dataType.slice(0, -1)} 失败`
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Add ${dataType} item error:`, error);
|
||||
console.error(`添加${dataType}物品错误:`, error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Add ${dataType} item error: ${error.message}`
|
||||
msg: `添加${dataType}物品错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -187,7 +187,7 @@ async function consumeInventoryItem(db, openid, dataType, itemId, count) {
|
||||
if (!validateDataType(dataType)) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: `Invalid data type: ${dataType}`
|
||||
msg: `无效的数据类型: ${dataType}`
|
||||
};
|
||||
}
|
||||
|
||||
@@ -195,14 +195,14 @@ async function consumeInventoryItem(db, openid, dataType, itemId, count) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "User not found"
|
||||
msg: "未找到用户"
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof count !== 'number' || count < 0) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: "Count must be a non-negative number"
|
||||
msg: "数量必须是非负数"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -210,16 +210,16 @@ async function consumeInventoryItem(db, openid, dataType, itemId, count) {
|
||||
if (currentCount < count) {
|
||||
return {
|
||||
code: -6,
|
||||
msg: `Insufficient ${dataType.slice(0, -1)} ${itemId}, current: ${currentCount}, required: ${count}`
|
||||
msg: `${dataType.slice(0, -1)} ${itemId}不足, 当前: ${currentCount}, 需要: ${count}`
|
||||
};
|
||||
}
|
||||
|
||||
return await addInventoryItem(db, openid, dataType, itemId, -count);
|
||||
} catch (error) {
|
||||
console.error(`Consume ${dataType} item error:`, error);
|
||||
console.error(`消耗${dataType}物品错误:`, error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Consume ${dataType} item error: ${error.message}`
|
||||
msg: `消耗${dataType}物品错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -238,7 +238,7 @@ async function setInventoryItem(db, openid, dataType, itemId, count) {
|
||||
if (!validateDataType(dataType)) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: `Invalid data type: ${dataType}`
|
||||
msg: `无效的数据类型: ${dataType}`
|
||||
};
|
||||
}
|
||||
|
||||
@@ -247,14 +247,14 @@ async function setInventoryItem(db, openid, dataType, itemId, count) {
|
||||
if (!user) {
|
||||
return {
|
||||
code: -4,
|
||||
msg: "User not found"
|
||||
msg: "未找到用户"
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof count !== 'number' || count < 0) {
|
||||
return {
|
||||
code: -3,
|
||||
msg: "Count must be a non-negative number"
|
||||
msg: "数量必须是非负数"
|
||||
};
|
||||
}
|
||||
|
||||
@@ -275,19 +275,19 @@ async function setInventoryItem(db, openid, dataType, itemId, count) {
|
||||
old_count: oldCount,
|
||||
new_count: count
|
||||
},
|
||||
msg: `${dataType.slice(0, -1)} ${itemId} set successfully`
|
||||
msg: `${dataType.slice(0, -1)} ${itemId} 设置成功`
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
code: -1,
|
||||
msg: `Set ${dataType.slice(0, -1)} fail`
|
||||
msg: `设置 ${dataType.slice(0, -1)} 失败`
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Set ${dataType} item error:`, error);
|
||||
console.error(`设置${dataType}物品错误:`, error);
|
||||
return {
|
||||
code: -5,
|
||||
msg: `Set ${dataType} item error: ${error.message}`
|
||||
msg: `设置${dataType}物品错误: ${error.message}`
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ const { DATA_VERSION } = require('../user_init_data');
|
||||
* @param {Object} extra 额外信息
|
||||
* @returns {Object} 响应对象
|
||||
*/
|
||||
function success(data = null, message = "Success", extra = {}) {
|
||||
function success(data = null, message = "成功", extra = {}) {
|
||||
return {
|
||||
code: 200,
|
||||
data: data,
|
||||
@@ -42,7 +42,7 @@ function error(code, message, data = null) {
|
||||
* @param {any} data 错误相关数据
|
||||
* @returns {Object} 响应对象
|
||||
*/
|
||||
function badRequest(message = "Bad request", data = null) {
|
||||
function badRequest(message = "请求参数错误", data = null) {
|
||||
return error(-3, message, data);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ function badRequest(message = "Bad request", data = null) {
|
||||
* @param {string} message 错误消息
|
||||
* @returns {Object} 响应对象
|
||||
*/
|
||||
function userNotFound(message = "User not found") {
|
||||
function userNotFound(message = "未找到用户") {
|
||||
return error(-4, message);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ function userNotFound(message = "User not found") {
|
||||
* @param {Error} err 错误对象
|
||||
* @returns {Object} 响应对象
|
||||
*/
|
||||
function systemError(message = "System error", err = null) {
|
||||
function systemError(message = "系统错误", err = null) {
|
||||
const errorData = err ? {
|
||||
error_message: err.message,
|
||||
error_stack: process.env.NODE_ENV === 'development' ? err.stack : undefined
|
||||
@@ -78,7 +78,7 @@ function systemError(message = "System error", err = null) {
|
||||
* @returns {Object} 响应对象
|
||||
*/
|
||||
function insufficientResource(resource, current = 0, required = 0) {
|
||||
return error(-6, `Insufficient ${resource}`, {
|
||||
return error(-6, `${resource}不足`, {
|
||||
resource: resource,
|
||||
current: current,
|
||||
required: required,
|
||||
@@ -93,7 +93,7 @@ function insufficientResource(resource, current = 0, required = 0) {
|
||||
* @returns {Object} 响应对象
|
||||
*/
|
||||
function resourceExists(resource, identifier = null) {
|
||||
return error(-7, `${resource} already exists`, {
|
||||
return error(-7, `${resource}已存在`, {
|
||||
resource: resource,
|
||||
identifier: identifier
|
||||
});
|
||||
@@ -106,7 +106,7 @@ function resourceExists(resource, identifier = null) {
|
||||
* @returns {Object} 响应对象
|
||||
*/
|
||||
function operationDenied(reason, data = null) {
|
||||
return error(-8, `Operation denied: ${reason}`, data);
|
||||
return error(-8, `操作被拒绝: ${reason}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +116,7 @@ function operationDenied(reason, data = null) {
|
||||
* @returns {Object} 响应对象
|
||||
*/
|
||||
function unknownCommand(command, availableCommands = []) {
|
||||
return error(-2, `Unknown command: ${command}`, {
|
||||
return error(-2, `未知命令: ${command}`, {
|
||||
command: command,
|
||||
available_commands: availableCommands
|
||||
});
|
||||
@@ -139,10 +139,10 @@ function wrapAsync(operation, operationName = "Operation") {
|
||||
}
|
||||
|
||||
// 如果是成功结果,包装为成功响应
|
||||
return success(result, `${operationName} completed successfully`);
|
||||
return success(result, `${operationName}成功完成`);
|
||||
} catch (error) {
|
||||
console.error(`${operationName} error:`, error);
|
||||
return systemError(`${operationName} failed`, error);
|
||||
console.error(`${operationName}错误:`, error);
|
||||
return systemError(`${operationName}失败`, error);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user