fix(server): 修复物品发送接口返回结果处理
- 将物品发送请求的参数格式从 { role, item: [itemId, itemNum] } 修改为 { role, item: [[itemId, itemNum]] }
- 添加对返回结果的处理,根据 result.data.result 判断发送是否成功
- 成功时返回原来的成功消息,失败时返回失败消息和具体错误内容
This commit is contained in:
@@ -30,7 +30,7 @@ router.post("/item/send", async (req, res) => {
|
|||||||
const role = roleId[0].id;
|
const role = roleId[0].id;
|
||||||
const result = await axios.post(
|
const result = await axios.post(
|
||||||
"http://192.168.25.110:19000/center/gm",
|
"http://192.168.25.110:19000/center/gm",
|
||||||
{ role, item: [itemId, itemNum] },
|
{ role, item: [[itemId, itemNum]] },
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json, text/plain, */*",
|
Accept: "application/json, text/plain, */*",
|
||||||
@@ -44,7 +44,8 @@ router.post("/item/send", async (req, res) => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
console.log("物品[%s]发送给[%s]结果:%s", itemId, roleName, result.data);
|
console.log("物品[%s]发送给[%s]结果:%s", itemId, roleName, result.data);
|
||||||
res.json({ code: 0, msg: "发送成功!" });
|
if (result.data.result) res.json({ code: 0, msg: "发送成功!" });
|
||||||
|
else res.json({ code: 1, msg: result.data.content });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("获取角色数据失败:", error);
|
console.error("获取角色数据失败:", error);
|
||||||
res.status(500).json({ error: "获取角色数据失败" });
|
res.status(500).json({ error: "获取角色数据失败" });
|
||||||
|
|||||||
Reference in New Issue
Block a user