[Glitch] Add missing rejection handling for Promises

Port missing parts from 2c51bc0ca5 to glitch-soc
This commit is contained in:
Thibaut Girka
2019-02-10 21:28:29 +01:00
parent 6b2eefc7bf
commit a963ea67dd
8 changed files with 54 additions and 29 deletions

View File

@ -1,4 +1,4 @@
import { showAlert } from 'flavours/glitch/actions/alerts';
import { showAlertForError } from 'flavours/glitch/actions/alerts';
const defaultFailSuffix = 'FAIL';
@ -8,21 +8,7 @@ export default function errorsMiddleware() {
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));
}
}