javascript - 502 Bad Gateway 和 503 Service Unavailable - 但不一致
问题描述
我有这个代码,一旦你输入了一个人的名字和职位,它就会遍历一个不同的表列表并记录它们,其中它将保存一些以后表单中的数据。问题是它只会创建一些记录,而其他记录会给我一个 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)
我不确定在哪里可以找到它。
解决方案
服务器是卑鄙的,您应该检查它是否运行正确且配置正确。真的没什么,500 范围意味着服务器做错了什么,或者是一个不使用正确状态代码的坏 api。
推荐阅读
- amazon-s3 - 何时使用 s3cmd 而不是以编程方式访问 S3 API?
- java - 使用流收集 HashMap 中的事件
- bash - 如何在 Bash 脚本中编写 3-4 提交以在 CircleCI 中启动不同类型的自动化 UI 测试?
- sql - 如何从 Array 中检索参数(BigQuery 中具有命中的 Google Analytics 表)?
- php - PHP 版本在 IIS 上不断从 7.1.1 切换到 5.4.45
- java - ScalaBuff 在解析 protobuf 文件时出错
- python - 如何让python将这两行识别为一句话
- c++ - Qt 抗锯齿设置不同的笔宽
- elasticsearch - 如何为 Elasticsearch 提供索引模板?
- reactjs - setState 不更新状态对象