【发布时间】:2019-11-25 21:12:32
【问题描述】:
在 Strapi 的管理界面中创建模型时,我有一些独特的字段。
我意识到在api调用期间没有提供字段时,它会给出500的错误消息,而不是正确的错误消息。
我确实明白为什么会出现错误,因为我可以在后端控制台中看到日志,并且我已经浏览了诸如 https://github.com/strapi/strapi/issues/1189 和 https://github.com/strapi/strapi/issues/1175 之类的帖子
阅读完这些问题后,我认为最好的方法是使用 /api/controllers 并创建一个诸如 create 之类的函数来覆盖提供的函数,但我收到 Model.create is not a function 的错误
我还没有在控制器中做太多事情,所以代码很精简。
module.exports = {
/* Strapi has default create function
* But because of the error message it provide is vague, will have to customize the controller */
create: async (ctx) => {
try {
console.log(ctx.request.body, 'ctx');
const article = await Article.create(ctx.request.body);
console.log(article, 'article');
} catch (e) {
console.log(e, 'error');
}
}
};
我已阅读问题单https://github.com/strapi/strapi/issues/1505
但我正在使用
带子:3.0.0-beta.17.5
节点:v10.17.0
npm:6.11.3
db:sqlite3(本地)postgresql(暂存)
有人知道我做错了什么吗?
提前感谢您的帮助和建议。
【问题讨论】:
标签: javascript database sql-insert bookshelf.js strapi