If there is a specific error it should be shown to the user (#5323)

e.g. post_is_deleted, or topic_must_be_open_to_vote
This commit is contained in:
Angus McLeod
2017-11-17 19:12:13 +08:00
committed by Régis Hanol
parent 3a472b507e
commit c8a6e5cbb3

View File

@ -3,6 +3,7 @@ import { h } from 'virtual-dom';
import { iconNode } from 'discourse-common/lib/icon-library'; import { iconNode } from 'discourse-common/lib/icon-library';
import RawHtml from 'discourse/widgets/raw-html'; import RawHtml from 'discourse/widgets/raw-html';
import { ajax } from 'discourse/lib/ajax'; import { ajax } from 'discourse/lib/ajax';
import { popupAjaxError } from 'discourse/lib/ajax-error';
import evenRound from "discourse/plugins/poll/lib/even-round"; import evenRound from "discourse/plugins/poll/lib/even-round";
import { avatarFor } from 'discourse/widgets/post'; import { avatarFor } from 'discourse/widgets/post';
import round from "discourse/lib/round"; import round from "discourse/lib/round";
@ -15,8 +16,12 @@ function fetchVoters(payload) {
return ajax("/polls/voters.json", { return ajax("/polls/voters.json", {
type: "get", type: "get",
data: payload data: payload
}).catch(() => { }).catch((error) => {
bootbox.alert(I18n.t('poll.error_while_fetching_voters')); if (error) {
popupAjaxError(error);
} else {
bootbox.alert(I18n.t('poll.error_while_fetching_voters'));
}
}); });
} }
@ -511,8 +516,12 @@ export default createWidget('discourse-poll', {
}).then(() => { }).then(() => {
poll.set('status', status); poll.set('status', status);
this.scheduleRerender(); this.scheduleRerender();
}).catch(() => { }).catch((error) => {
bootbox.alert(I18n.t("poll.error_while_toggling_status")); if (error) {
popupAjaxError(error);
} else {
bootbox.alert(I18n.t("poll.error_while_toggling_status"));
}
}).finally(() => { }).finally(() => {
state.loading = false; state.loading = false;
}); });
@ -570,8 +579,12 @@ export default createWidget('discourse-poll', {
} }
}).then(() => { }).then(() => {
state.showResults = true; state.showResults = true;
}).catch(() => { }).catch((error) => {
bootbox.alert(I18n.t("poll.error_while_casting_votes")); if (error) {
popupAjaxError(error);
} else {
bootbox.alert(I18n.t("poll.error_while_casting_votes"));
}
}).finally(() => { }).finally(() => {
state.loading = false; state.loading = false;
}); });