首先,我知道我必须return
承诺避免此警告。我也尝试按照建议的here in the docs返回null
。考虑这段代码,我使用它在猫鼬的预存挂钩,但我已经经历了在其他地方这样的警告:蓝鸟 - 一个承诺是在处理程序中创建的,但没有从它返回
var Story = mongoose.model('Story', StorySchema);
StorySchema.pre('save', function(next) {
var story = this;
// Fetch all stories before save to automatically assign
// some variable, avoiding conflict with other stories
return Story.find().then(function(stories) {
// Some code, then set story.somevar value
story.somevar = somevar;
return null;
}).then(next).catch(next); // <-- this line throws warning
});
我也试过(最初)是这样的:
story.somevar = somevar;
return next(); // <-- this line throws warning
}).catch(next);
但它也不起作用。哦,我不得不提,那我用蓝鸟:
var Promise = require('bluebird'),
mongoose = require('mongoose');
mongoose.Promise = Promise;
不是A promise was created in a handler but was not returned from it重复,那家伙忘记返回一个承诺。
[从成功的jQuery AJAX POST蓝鸟未处理的废品(的可能的复制http://stackoverflow.com/questions/33948597/bluebird-unhandled防止警告-rejection-error-from-successful-jquery-ajax-post) – TylerH