【发布时间】:2019-12-21 23:36:38
【问题描述】:
我在我的 Express API 上有一个简单的 put 请求,在我使用 Sequelize ORM 进行更新后,我无法使用 Socket.io 发出。
我只能发出其他对象,例如,我可以发出这个 {"hello": "world"},但我不能发出更新的结果。
这是代码块:
module.exports = {
async update(req, res) {
const { body } = req;
const { task_id } = req.params;
const task = await ProjectTask.findByPk(task_id);
task.update({
name: body.title,
description: body.description,
});
req.io.emit('update', task); // Here it is the socket.io that brakes the code
console.log(task); // this works
return res.json(task); // also this
},
}
错误: (节点:8923)UnhandledPromiseRejectionWarning:RangeError:超出最大调用堆栈大小 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:99:24) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:126:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) 在 _removeBlobs (/Users/guifeliper/nodejs/node_modules/socket.io-parser/binary.js:130:9) (节点:8923)UnhandledPromiseRejectionWarning:未处理的承诺拒绝。此错误源于在没有 catch 块的情况下抛出异步函数内部,或拒绝未使用 .catch() 处理的承诺。 (拒绝编号:1) (节点:8923)[DEP0018] DeprecationWarning:不推荐使用未处理的承诺拒绝。将来,未处理的 Promise 拒绝将使用非零退出代码终止 Node.js 进程。
编辑:可能是因为项目格式? 这就是我们在任务变量上的内容:
{
"id": 10971,
"name": "Change the background image 5",
"description": "save description 2",
"dueEndDate": null,
"status": 3,
"deleted": {
"type": "Buffer",
"data": [
0
]
},
"closed": {
"type": "Buffer",
"data": [
0
]
},
"createdAt": "2019-12-18T16:06:57.000Z",
"modifiedAt": "2019-12-21T14:43:39.000Z",
"sprint_id": 41
}
未解析:
ProjectTask {
dataValues:
{ id: 10971,
name: 'Change the background image 5',
description: 'save description 2',
dueEndDate: null,
status: 3,
deleted: <Buffer 00>,
closed: <Buffer 00>,
createdAt: 2019-12-18T16:06:57.000Z,
modifiedAt: 2019-12-21T14:43:39.000Z,
sprint_id: 41 },
_previousDataValues:
{ id: 10971,
name: 'Change the background image 5',
description: 'save description 2',
dueEndDate: null,
status: 3,
deleted: <Buffer 00>,
closed: <Buffer 00>,
createdAt: 2019-12-18T16:06:57.000Z,
modifiedAt: 2019-12-21T14:43:39.000Z,
sprint_id: 41 },
_changed: {},
_modelOptions:
{ timestamps: true,
validate: {},
freezeTableName: true,
underscored: false,
paranoid: false,
rejectOnEmpty: false,
whereCollection: { id: '10971' },
schema: null,
schemaDelimiter: '',
defaultScope: {},
scopes: {},
indexes: [],
name: { plural: 'ProjectTasks', singular: 'ProjectTask' },
omitNull: false,
createdAt: 'createdAt',
updatedAt: 'modifiedAt',
sequelize:
Sequelize {
options: [Object],
config: [Object],
dialect: [MysqlDialect],
queryInterface: [QueryInterface],
models: [Object],
modelManager: [ModelManager],
connectionManager: [ConnectionManager],
importCache: {} },
hooks: {} },
_options:
{ isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes:
[ 'id',
'name',
'description',
'dueEndDate',
'status',
'deleted',
'closed',
'createdAt',
'modifiedAt',
'sprint_id' ] },
isNewRecord: false }
【问题讨论】:
-
显示
task的内容。 -
也添加了未解析的版本,谢谢 Marcos。
-
这就是问题所在。检查我的答案。
标签: node.js express socket.io sequelize.js