In my application I have a problem in displaying the error message. I have a function, in which file uploaded is converted from one file format to another. It should throw the message if the file is correctly converted or not.
Following is how I am throwing the message. I don’t want to use console.log. I want to throw Error/alert.
if (error) {
throw (new Meteor.Error(“There’s some error in converting file”));
} else {
console.log(“File has been converted”);
}
Also, I have posted the question on stackoverflow, but unable to get any help Throwing Error. Please help me out.
Meteor.Error is a server-side way of sending a thrown error over DDP to the client. Most often it is used within the context of a call to a method:
On the server:
Meteor.methods({
myMethod: function(params) {
// do stuff
...
// something bad happened: throw a Meteor.error:
throw new Meteor.Error('bad', 'stuff happened');
});
and on the client:
Meteor.call('myMethod', params, function(error, result) {
if (error) {
// This is where we see that thrown Meteor.Error from the method
} else {
// Do stuff with result
}
});
If you want a conventionally thrown error, use the standard JavaScript throw new Error()
I am trying the same way but unable to get the message. I am adding the code for both the client and the server side. Sorry, for adding too much of the code but I am unable to figure out where I am commiting the mistake. Please help and tell where I am going wrong. Here is the code Test
@TwinTails I have followed as per the documentation and as per your suggestions (line 36) I have edited the code too. Following is the code, and console o/p. It shows the error on console but no error is shown, and follows the next steps.
Server
if (error) {
throw new Meteor.Error("logg", "truth");
} else {
console.log("File has been converted" + objects[i] + i);
Client
Meteor.call('convertFile', function (error) {
if (error.error === "logg") {
alert("Error");
};
});
Terminal
I20150623-00:25:43.007(5.5)? Exception in callback of async function:
Error: truth [logg]
I20150623-00:25:43.007(5.5)? at app/server/cfs_uploader.js:80:15
I20150623-00:25:43.007(5.5)? at runWithEnvironment
(packages/meteor/dynamics_nodejs.js:108:1)
I20150623-00:25:43.007(5.5)? Exception in callback of async function:
Error: truth [logg]
I20150623-04:38:34.642(5.5)? Exception in callback of async function: Error: trust [logg]
I20150623-04:38:34.642(5.5)? at app/server/cfs_uploader.js:80:15
I20150623-04:38:34.642(5.5)? at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108:1)
I20150623-04:38:34.642(5.5)? Exception in callback of async function: Error: trust [logg]
I20150623-04:38:34.642(5.5)? at app/server/cfs_uploader.js:80:15
I20150623-04:38:34.642(5.5)? at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108:1)