获取"无效的退出定义"编译Sails Helper(Sails v1.0)

时间:2017-10-31 12:26:33

标签: sails.js

我收到了错误

Invalid exit definition ("success").  Must be a dictionary-- i.e. plain JavaScript object like `{}`.
Invalid exit definition ("error").  Must be a dictionary-- i.e. plain JavaScript object like `{}`.

执行sails lift时。错误发生在getRole.js

module.exports = {


  friendlyName: 'Get Role',


  description: '',


  inputs: {
    user_id: {
      friendlyName: 'User Id',
      description: 'The ID of the user to check role',
      type: 'string',
      required: true
    }
  },

  exits: {
    success: function (role){
      return role;
    },
    error: function (message) {
      return message;
    }
  },


  fn: function (inputs, exits) {
    User.findOne({ id: inputs.user_id } , function (err, user) {
      if (err) return exits.err(err);
      return exits.success(user.role);
    });
  }
};

这是一个新错误,看着我的git,我的代码中没有任何变化,因为它成功编译了。我理解我在测试版中使用的Sails版本(v1.0),所以我考虑到了这一点。

2 个答案:

答案 0 :(得分:0)

退出不能定义为功能。有一种特殊的语法(Machine Spec)来定义出口。在你的例子中,这应该有效:

exits: {
    error: {
        description: 'Unexpected error occurred.',
    },

    success: {
        description: 'Role was succesffuly fetched'
    }
},

您可以在此处阅读有关帮助程序退出的更多信息:https://next.sailsjs.com/documentation/concepts/helpers

答案 1 :(得分:0)

可能会在最后一个版本1.0.0-38上发生更改。我还没有在下面检查过,但是执行帮助程序的方式发生了变化:在.exec()我收到了错误。现在,使用.switch();