How to display an error message to user?

On my website a user can enter a string, that string gets sent from the client to the server through a Meteor method and then inserted into the Collection. How would one display a little box with an error to the user if this string already exists in the Collection? I know how to check if it is the same just not how to display the error. The functionality is similar to “This username is already taken” type stuff that shows up on websites.

take a look at http://messageformat.meteor.com/docs#quickstart

On the server method you check if it exists, then you
throw new Meteor.Error(500, 'Already exists');

Then on the client you catch if like so

Meteor.call('insertSomething', someString, function (err, res) {
	if (err) {
		alert(err.message);
	}
});
1 Like