+import { defineMessages } from 'react-intl';
+
+const messages = defineMessages({
+ unexpectedTitle: { id: 'alert.unexpected.title', defaultMessage: 'Oops!' },
+ unexpectedMessage: { id: 'alert.unexpected.message', defaultMessage: 'An unexpected error occurred.' },
+});
+
export const ALERT_SHOW = 'ALERT_SHOW';
export const ALERT_DISMISS = 'ALERT_DISMISS';
export const ALERT_CLEAR = 'ALERT_CLEAR';
message,
};
};
+
+export function showAlertForError(error) {
+ if (error.response) {
+ const { data, status, statusText } = error.response;
+
+ let message = statusText;
+ let title = `${status}`;
+
+ if (data.error) {
+ message = data.error;
+ }
+
+ return showAlert(title, message);
+ } else {
+ console.error(error);
+ return showAlert(messages.unexpectedTitle, messages.unexpectedMessage);
+ }
+}
import api from 'flavours/glitch/util/api';
-import { CancelToken } from 'axios';
+import { CancelToken, isCancel } from 'axios';
import { throttle } from 'lodash';
import { search as emojiSearch } from 'flavours/glitch/util/emoji/emoji_mart_search_light';
import { useEmoji } from './emojis';
import resizeImage from 'flavours/glitch/util/resize_image';
import { updateTimeline } from './timelines';
+import { showAlertForError } from './alerts';
let cancelFetchComposeSuggestionsAccounts;
},
}).then(response => {
dispatch(readyComposeSuggestionsAccounts(token, response.data));
+ }).catch(error => {
+ if (!isCancel(error)) {
+ dispatch(showAlertForError(error));
+ }
});
}, 200, { leading: true, trailing: true });
import api from 'flavours/glitch/util/api';
+import { showAlertForError } from './alerts';
export const LIST_FETCH_REQUEST = 'LIST_FETCH_REQUEST';
export const LIST_FETCH_SUCCESS = 'LIST_FETCH_SUCCESS';
};
api(getState).get('/api/v1/accounts/search', { params })
- .then(({ data }) => dispatch(fetchListSuggestionsReady(q, data)));
+ .then(({ data }) => dispatch(fetchListSuggestionsReady(q, data)))
+ .catch(error => dispatch(showAlertForError(error)));
};
export const fetchListSuggestionsReady = (query, accounts) => ({
pushNotificationsSetting.remove(me);
}
- try {
- getRegistration()
- .then(getPushSubscription)
- .then(unsubscribe);
- } catch (e) {
-
- }
- });
+ return getRegistration()
+ .then(getPushSubscription)
+ .then(unsubscribe);
+ })
+ .catch(console.warn);
} else {
console.warn('Your browser does not support Web Push Notifications.');
}
if (me) {
pushNotificationsSetting.set(me, data);
}
- });
+ }).catch(console.warn);
};
}
import api from 'flavours/glitch/util/api';
import { debounce } from 'lodash';
+import { showAlertForError } from './alerts';
export const SETTING_CHANGE = 'SETTING_CHANGE';
export const SETTING_SAVE = 'SETTING_SAVE';
const data = getState().get('settings').filter((_, path) => path !== 'saved').toJS();
- api(getState).put('/api/web/settings', { data }).then(() => dispatch({ type: SETTING_SAVE }));
+ api(getState).put('/api/web/settings', { data })
+ .then(() => dispatch({ type: SETTING_SAVE }))
+ .catch(error => dispatch(showAlertForError(error)));
}, 5000, { trailing: true });
export function saveSettings() {
import { changeLocalSetting } from 'flavours/glitch/actions/local_settings';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { boostModal, favouriteModal, deleteModal } from 'flavours/glitch/util/initial_state';
+import { showAlertForError } from '../actions/alerts';
const messages = defineMessages({
deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
},
onEmbed (status) {
- dispatch(openModal('EMBED', { url: status.get('url') }));
+ dispatch(openModal('EMBED', {
+ url: status.get('url'),
+ onError: error => dispatch(showAlertForError(error)),
+ }));
},
onDelete (status, history, withRedraft = false) {
static propTypes = {
url: PropTypes.string.isRequired,
onClose: PropTypes.func.isRequired,
+ onError: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
}
iframeDocument.body.style.margin = 0;
this.iframe.width = iframeDocument.body.scrollWidth;
this.iframe.height = iframeDocument.body.scrollHeight;
+ }).catch(error => {
+ this.props.onError(error);
});
}
-import { showAlert } from 'flavours/glitch/actions/alerts';
+import { showAlertForError } from 'flavours/glitch/actions/alerts';
const defaultFailSuffix = 'FAIL';
const isFail = new RegExp(`${defaultFailSuffix}$`, 'g');
if (action.type.match(isFail)) {
- if (action.error.response) {
- const { data, status, statusText } = action.error.response;
-
- let message = statusText;
- let title = `${status}`;
-
- if (data.error) {
- message = data.error;
- }
-
- dispatch(showAlert(title, message));
- } else {
- console.error(action.error);
- dispatch(showAlert('Oops!', 'An unexpected error occurred.'));
- }
+ dispatch(showAlertForError(action.error));
}
}