Better error return in subscriptions

This commit is contained in:
vjrj 2018-03-02 10:08:52 +01:00
parent 9062012d18
commit 8deaafb96b
2 changed files with 16 additions and 14 deletions

View file

@ -17,21 +17,21 @@ Meteor.methods({
distance: Number
});
const type = 'web';
const newDoc = {
owner: this.userId,
type,
geo: geo(doc),
...doc
};
// console.log(newDoc);
const already = Subscriptions.findOne(newDoc);
if (already) {
throw new Meteor.Error('on-already-subscribed', 'The user is already subscribed to this area');
}
try {
const newDoc = {
owner: this.userId,
type,
geo: geo(doc),
...doc
};
// console.log(newDoc);
const already = Subscriptions.findOne(newDoc);
if (already) {
throw new Meteor.Error('500', 'on-already-subscribed');
}
return Subscriptions.insert(newDoc);
} catch (exception) {
console.error(exception);
// console.error(exception);
throw new Meteor.Error('500', exception);
}
},