【发布时间】:2016-05-19 13:53:58
【问题描述】:
有人能告诉我为什么meteor.js v1.3 中的这个方法调用在运行时没有向我的终端输出任何console.logs 吗?当我不使用验证方法时,此方法在不同的流星项目中效果很好,并且 Emails.insert 函数有效,但是当我添加 HTTP.post 函数时,它失败但我无法弄清楚如何显示错误,因为console.log(error) 和 Meteor.throw(error) 都不会在我的服务器终端中显示任何内容。谢谢!
import { Emails } from './emails';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { ValidatedMethod } from 'meteor/mdg:validated-method';
import { HTTP } from 'meteor/http';
export const insertEmail = new ValidatedMethod({
name: 'emails.insert',
validate: new SimpleSchema({
email: { type: String }
}).validator(),
run(email) {
let isPresent = Emails.find({email: email.email}).fetch();
if(isPresent < 1){
Emails.insert({email: email.email, ip: '1'});
HTTP.post('https://api.sendgrid.com/v3/contactdb/recipients', {
headers: {
Authorization: "Bearer "+Meteor.settings.private.sendGridMarketingKey,
'Content-Type': 'application/json'
},
content: '[{\"email\": \"'+email+'\"}]'
},function( error, response ) {
if ( error ) {
throw new Meteor.Error(500, error);
console.log( error );
} else {
throw new Meteor.Error(500, response);
console.log( response );
}
});
} else {
throw new Meteor.Error(500, 'This Email is Already Added!')
}
},
});
【问题讨论】:
标签: javascript meteor reactjs