まず、この警告を避けることを約束します。return
また、null
をhere in the docsとして返してみました。コードのこの部分を考えてみましょう、私はマングースの事前セーブフックでそれを使用していますが、私は他の場所でこの警告を経験した:Bluebird - ハンドラで約束が作成されましたが、返されませんでした
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の複製、男は約束を返すのを忘れていました。
可能な複製を使用して警告を防ぐことができるはずです(http://stackoverflow.com/questions/33948597/bluebird-unhandled -rejection-error-from-jquery-ajax-post) – TylerH