Better error return in subscriptions
This commit is contained in:
parent
9062012d18
commit
8deaafb96b
2 changed files with 16 additions and 14 deletions
|
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -40,8 +40,10 @@ class SubscriptionEditor extends React.Component {
|
|||
Meteor.call(methodToCall, doc, (error, subscriptionId) => {
|
||||
if (error) {
|
||||
self.setState({ disableFstBtn: false });
|
||||
if (error.reason && error.reason.reason) {
|
||||
Bert.alert(t(error.reason.reason), 'danger');
|
||||
if (error.error && error.error === 'on-already-subscribed') {
|
||||
Bert.alert(t(error.error), 'danger');
|
||||
} else if (error.reason) {
|
||||
Bert.alert(error.reason, 'danger');
|
||||
}
|
||||
} else {
|
||||
self.setState({ disableFstBtn: false });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue