【问题标题】:How to display server side errors in meteor如何在流星中显示服务器端错误
【发布时间】: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


    【解决方案1】:

    throw 退出 Javascript 中的函数。将您的console.log 放在throw 之前。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 2017-03-03
      • 2013-10-03
      • 1970-01-01
      • 2021-11-11
      • 2015-06-24
      相关资源
      最近更新 更多