![](/img/trans.png)
[英]How to display server side validation errors with onFailure() in Edit/Create components?
[英]How to display server side errors in meteor
有人可以告诉我为什么meteor.js v1.3中的此方法调用在运行时没有将任何console.logs输出到我的终端吗? 当我不使用validatedmethod时,此方法在另一个流星项目中效果很好,并且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!')
}
},
});
throw
退出Javascript函数。 将console.log
放在throw
之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.