SQL Server NodeJS (Express js)-我可以使用console.log记录错误,但在postman中无法读取错误

mutmk8jj  于 2022-12-10  发布在  Postman
关注(0)|答案(1)|浏览(102)

I am doing custom post API, I can able to log and read the error but when I tried to send it through res.send(err) and when I checked it in postman, I only see an empty object in errorMessage in variable out. Can anyone please help me out.
Here is my code

const insertItemDetails = async (body, res) => {
  const table = new sql.Table("table_name");
  table.create = false;
  table.columns.add("jsuordref", sql.VarChar(50), {
    nullable: false,
    primary: true,
  });
  table.columns.add("itemno", sql.Int, {
    nullable: false,
    primary: true,
  });
  table.columns.add("apispec", sql.VarChar(250), { nullable: false });
  table.columns.add("customerspec", sql.VarChar(250), { nullable: false });
  table.columns.add("grade", sql.VarChar(50), { nullable: false });
  let dDate = Date();
  console.log("this is --------------_______>>>" + dDate);
  let smalldate = moment(dDate).format("YYYY-MM-DD");
  let tmstpDate = moment(dDate).format("YYYY-MM-DD HH:mm:ss:SSSS");

  for (let i = 0; i < body.itemDetails.length; i++) {
    table.rows.add(
      body.itemDetails[i].jsuNumber,
      body.itemDetails[i].itemNo,
      body.itemDetails[i].apiSpec,
      body.itemDetails[i].customerSpec,
      body.itemDetails[i].grade
    );
  }
  const request = new sql.Request();
  request.bulk(table, (err, rows) => {
    if (!err) {
      var out = {
        code: 200,
        status: "OK",
        message: "JSUOrder successfully created!!",
        jsuOrder: body.jsuNumber,
        response: rows,
      };
    } else {
      var out = {
        code: 400,
        message:
          "Something went wrong while uploading Item Details, Please contact IT",
        errorMessage: { err },
      };
    }
    console.log(err);
    res.send(out);
  });
};
olhwl3o2

olhwl3o21#

You are sending
errorMessage: { err },
you should be sending
errorMessage: err,
for the error object to be displayed.
remove "{ }" around err object

相关问题