【问题标题】:502 Bad Gateway and 503 Service Unavailable - But it's Inconsistent502 Bad Gateway 和 503 Service Unavailable - 但不一致
【发布时间】:2021-02-12 21:41:29
【问题描述】:

我有这个代码,一旦你输入了一个人的姓名和职位,它就会遍历一个不同的表列表并记录它们,其中它将保存一些以后表单中的数据。问题是它只会创建一些记录,而其他记录会给我一个 502 或 503 错误。而且是不一致的。它可能会按预期创建 3 或 4 条记录,但每次都会创建不同的 3 或 4 条。 502 和 503 错误每次发生在不同的调用上。所以我知道代码本身确实有效,实际上它在我的本地构建中完美运行。但在我的生产版本中,会发生这种情况。

我确信有一种更有效的方法可以做到这一点,所以我也很高兴听到这方面的想法。我有多个表的唯一原因是我们的表单上有大约 200 个字段,而 mySql 不允许我将它们全部放在一起。

代码如下:

createQuestions() {
    fetch(
      API_URL + `/interview/create/questions/${this.state.lastEmployeeId}`,
      {
        method: "PUT",
        body: JSON.stringify({
          lastEmployeeId: this.state.lastEmployeeId,
          table: "audit_general",
        }),
        headers: { "Content-Type": "application/json" },
      }
    )
      .then((res) => {
        if (!res.ok) {
          throw new Error();
        }
        return res.json();
      })
      .then((data) => console.log(data))
      .catch((err) => console.log(err))
      .then(
        fetch(
          API_URL + `/interview/create/questions/${this.state.lastEmployeeId}`,
          {
            method: "PUT",
            body: JSON.stringify({
              lastEmployeeId: this.state.lastEmployeeId,
              table: "audit_culture",
            }),
            headers: { "Content-Type": "application/json" },
          }
        )
          .then((res) => {
            if (!res.ok) {
              throw new Error();
            }
            return res.json();
          })
          .then((data) => console.log(data))
          .catch((err) => console.log(err))
      )
      .then(
        fetch(
          API_URL + `/interview/create/questions/${this.state.lastEmployeeId}`,
          {
            method: "PUT",
            body: JSON.stringify({
              lastEmployeeId: this.state.lastEmployeeId,
              table: "audit_performance",
            }),
            headers: { "Content-Type": "application/json" },
          }
        )
          .then((res) => {
            if (!res.ok) {
              throw new Error();
            }
            return res.json();
          })
          .then((data) => console.log(data))
          .catch((err) => console.log(err))
      )
      .then(
        fetch(
          API_URL + `/interview/create/questions/${this.state.lastEmployeeId}`,
          {
            method: "PUT",
            body: JSON.stringify({
              lastEmployeeId: this.state.lastEmployeeId,
              table: "audit_policies",
            }),
            headers: { "Content-Type": "application/json" },
          }
        )
          .then((res) => {
            if (!res.ok) {
              throw new Error();
            }
            return res.json();
          })
          .then((data) => console.log(data))
          .catch((err) => console.log(err))
      )
      .then(
        fetch(
          API_URL + `/interview/create/questions/${this.state.lastEmployeeId}`,
          {
            method: "PUT",
            body: JSON.stringify({
              lastEmployeeId: this.state.lastEmployeeId,
              table: "audit_risk",
            }),
            headers: { "Content-Type": "application/json" },
          }
        )
          .then((res) => {
            if (!res.ok) {
              throw new Error();
            }
            return res.json();
          })
          .then((data) => console.log(data))
          .catch((err) => console.log(err))
      )
      .then(
        fetch(
          API_URL + `/interview/create/questions/${this.state.lastEmployeeId}`,
          {
            method: "PUT",
            body: JSON.stringify({
              lastEmployeeId: this.state.lastEmployeeId,
              table: "audit_strategy",
            }),
            headers: { "Content-Type": "application/json" },
          }
        )
          .then((res) => {
            if (!res.ok) {
              throw new Error();
            }
            return res.json();
          })
          .then((data) => console.log(data))
          .catch((err) => console.log(err))
      )
      .then(
        fetch(
          API_URL + `/interview/create/questions/${this.state.lastEmployeeId}`,
          {
            method: "PUT",
            body: JSON.stringify({
              lastEmployeeId: this.state.lastEmployeeId,
              table: "audit_rewards",
            }),
            headers: { "Content-Type": "application/json" },
          }
        )
          .then((res) => {
            if (!res.ok) {
              throw new Error();
            }
            return res.json();
          })
          .then((data) => console.log(data))
          .catch((err) => console.log(err))
      )
      .then(
        fetch(
          API_URL + `/interview/create/questions/${this.state.lastEmployeeId}`,
          {
            method: "PUT",
            body: JSON.stringify({
              lastEmployeeId: this.state.lastEmployeeId,
              table: "audit_workforce",
            }),
            headers: { "Content-Type": "application/json" },
          }
        )
          .then((res) => {
            if (!res.ok) {
              throw new Error();
            }
            return res.json();
          })
          .then((data) => console.log(data))
          .catch((err) => console.log(err))
      );
  }
}

我得到了一些错误:

List.js:401 PUT https://ppr-team.com/api/interview/create/questions/41 502 (Bad Gateway)

List.js:443 PUT https://ppr-team.com/api/interview/create/questions/41 502 (Bad Gateway)

List.js:422 PUT https://ppr-team.com/api/interview/create/questions/41 502 (Bad Gateway)

List.js:464 PUT https://ppr-team.com/api/interview/create/questions/41 503 (Service Unavailable)

List.js:485 PUT https://ppr-team.com/api/interview/create/questions/41 503 (Service Unavailable)

我不知道在哪里可以找到它。

【问题讨论】:

    标签: javascript mysql reactjs api


    【解决方案1】:

    服务器不正常,您应该检查它是否运行正确且配置正确。真的没什么,500 范围意味着服务器做错了,要么是错误的 api,要么没有使用正确的状态代码。

    【讨论】:

    • 我在我的几个表中添加了一些列。有什么变化可能导致这种情况吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    • 2019-03-07
    • 1970-01-01
    • 2019-07-15
    • 1970-01-01
    • 2019-09-15
    • 1970-01-01
    相关资源
    最近更新 更多