我想在我的应用程序中实现错误处理,但是当我抛出 Meteor.Error 时,我的服务器崩溃了。这可能是因为我正在使用未来来等待结果。我怎样才能让它运行?
Meteor.methods({
'/app/pdf/download': function (url, name) {
check(url, String);
check(name, Match.Any);
if ( ! name) {
name = url.split('/').pop();
} else {
name += '.pdf';
}
var Future = Meteor.npmRequire('fibers/future');
var Download = Meteor.npmRequire('download');
var future = new Future();
var download = new Download({ extract: true, strip: 1 })
.get(url)
.dest(process.env.PWD + '/staticFiles')
.rename(name);
// Run download
download.run(function (err, files, stream) {
if (err) {
throw new Meteor.Error(500, 'Couldn\'t download file');
}
future.return(name);
});
return future.wait();
}
});