带邮递员的Req.body UnhandledPromiseRejectionWarning:TypeError:无法解构'req.body'的属性'id',因为它是未定义的

时间:2020-08-04 12:27:20

标签: javascript node.js backend

我正在尝试通过POSTMAN向我的后端发出放置请求,这似乎是一个问题,我认为这很愚蠢,但我没有找到它。它说:“ UnhandledPromiseRejectionWarning:TypeError:无法解构'req.body'的属性'id',因为它未定义。”

router.put("/todos/", async (req, res, next) => {
  const { id, content } = req.body;
  try {
    const todo = (DUMMY_PLACES = {
      ...state,
      allIds: [...state.allIds, id],
      byIds: {
        ...state.byIds,
        [id]: {
          content,
          completed: false,
        },
      },
    });
    return success(res, todo);
  } catch (err) {
    next({ status: 400, message: "failed to update todo" });
  }
});

邮递员中的请求

{
    "id": 6,
    "content": "asd"
  }

DUMMYDB的外观

const DUMMY_PLACES = [
  {
    todos: {
      allIds: [1, 2, 3, 4],
      byIds: {
        "1": {
          content: "test1",
          completed: false,
        },
        "2": {
          content: "test2",
          completed: false,
        },
        "3": {
          content: "test3\\",
          completed: false,
        },
        "4": {
          content: "test4",
          completed: false,
        },
      },
    },
    visibilityFilter: "all",
  },
];

0 个答案:

没有答案