I want to suppress a server method call error since the error is non-critical and I want my method to continue running.
I’ve tried to create a new Meteor.Error object (see code below) and throw that but that seems not to work at all. I always get an Error 500 whether I provide a custom Meteor.Error object or leave it empty without throwing anything.
How do I suppress the error entirely to not get any error?
server\get_items.js
Meteor.http.get(endpoint, function (error, results) {
if (error) {
throw new Meteor.Error("error-fetching-item", "Error while importing item");
};
....
});
client\get_items.js
Meteor.call("myServerMethod", {
option_one: "option_one",
option_two: "option_two",
},
function (error) {
if (error) {
... // This always fires with an Error 500
} else {
...
}
}
);
as @eldog points out, you should use the synchronous (fibers)-way. In your second example the method returns before the error is thrown, so the client will never get the error.
@hwillson thanks for the step-by-step answer! You were right when you said I shouldn’t be seeing the error if I choose ignore it on the server.
Throwing it back to the client actually stops the execution on the server. The underlying problem that I kept getting an ERROR 500 was totally different from the issue I was asking above and fixing that issue brought back the normal behaviour of ignoring the error.
server\get_items.js
Meteor.http.get(endpoint, function (error, results) {
if (error) {
console.log("Error while importing item");
};
....
});
The above doesn’t interrupt the execution of the server method nor does it raise an error in the client.