I have a few unique fields when creating model in strapi's admin ui.
(在Stradi的管理ui中创建模型时,我有几个独特的字段。)
I realized that when field is not provided during the api call, it'll give an error message of 500
instead of the proper error message.
(我意识到当在api调用期间未提供field时,它将给出一条错误消息500
而不是正确的错误消息。)
I do understand why there's an error since I can see the log in backend console and I have scanned through posts such as https://github.com/strapi/strapi/issues/1189 and https://github.com/strapi/strapi/issues/1175
(我确实了解为什么会出错,因为我可以在后端控制台中看到日志,并且已经浏览了https://github.com/strapi/strapi/issues/1189和https://github.com/strapi/绑架/问题/ 1175)
After reading those issues, I believe the best way is to go /api/controllers
and create a function such as create
to override the one provided but I get an error of Model.create is not a function
(阅读完这些问题后,我相信最好的方法是转到/api/controllers
并创建一个函数(例如create
以覆盖提供的函数,但是出现Model.create is not a function
错误, Model.create is not a function
)
I have not do much in the controller yet so code is slim.
(我在控制器中没有做太多事情,因此代码很苗条。)
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');
}
}
};
I have read the issue ticket https://github.com/strapi/strapi/issues/1505
But I am using strapi: 3.0.0-beta.17.5 node: v10.17.0 npm: 6.11.3 db: sqlite3 (local) postgresql (staging)
(我已经阅读了问题单https://github.com/strapi/strapi/issues/1505
但我使用的是trapi:3.0.0-beta.17.5节点:v10.17.0 npm:6.11.3 db:sqlite3(本地) PostgreSQL(暂存))
Anyone know what I might have done wrong?
(有人知道我做错了吗?)
Thanks in advance for any help and advise.
(在此先感谢您的帮助和建议。)
ask by Dora translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…