[Glitch] Add missing rejection handling for Promises
Port missing parts from 2c51bc0ca5
to glitch-soc
This commit is contained in:
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user