方法中抛出的错误

方法中抛出的错误

本文介绍了如何查看 Meteor 方法中抛出的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查看 Meteor.Error 的实例以及抛出的任何其他内容.在服务器端,我正在查看运行 meteor 命令后打印到控制台的内容(在 localhost:3000 上开发).在客户端,我正在查看 JS 控制台.

I'd like to see instances of Meteor.Error as well as anything else that is thrown. On the server side, I'm looking at what is printed out to the console after running the meteor command (in development on localhost:3000). On the client, I'm looking at the JS console.

当客户端抛出 Meteor.Error 时,我在客户端控制台上看到它.当在服务器上抛出 Meteor.Error 时,我在任何一侧都看不到任何东西.当任何一侧抛出其他类型的错误时(例如,带有 mrt assert 包的 assert(false)),我在任何一侧都看不到它.

When a Meteor.Error is thrown on the client, I see it on the client console. When a Meteor.Error is thrown on the server, I see nothing on either side. When other types of errors are thrown on either side (for example, assert(false) with the mrt assert package), I see it on neither side.

推荐答案

这取决于你在哪里抛出 Meteor.Error,它需要一个上下文来提供给客户端.

It depends where you throw the Meteor.Error, it needs a context to give to the client.

如果你在一个方法中抛出一个 Meteor.Error,你会看到它在客户端调用回调的 err 中返回.例如

If you throw a Meteor.Error in a method you will see it come back in the err of the callback of the client side call. e.g

服务端

Meteor.methods({
    'crashme':function() {
        throw new Meteor.Error(500, "Error Title", "details", "more details");
    }
});

客户端

Meteor.call("crashme", function(err, result) {
    console.log(err);
    //--> Prints the thrown error
});

这篇关于如何查看 Meteor 方法中抛出的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 22:03