fix(response handling): Handle success responses better

This commit is contained in:
Stuart Taylor
2018-07-27 12:58:12 +01:00
committed by Mrugesh Mohapatra
parent b7aee9928e
commit ca70573bd8

View File

@ -14,6 +14,7 @@ import uuid from 'uuid/v4';
import { types, onlineStatusChange, isOnlineSelector } from './'; import { types, onlineStatusChange, isOnlineSelector } from './';
import postUpdate$ from '../../templates/Challenges/utils/postUpdate$'; import postUpdate$ from '../../templates/Challenges/utils/postUpdate$';
import { isGoodXHRStatus } from '../../templates/Challenges/utils';
const key = 'fcc-failed-updates'; const key = 'fcc-failed-updates';
@ -24,10 +25,12 @@ function delay(time = 0, fn) {
function failedUpdateEpic(action$, { getState }) { function failedUpdateEpic(action$, { getState }) {
const storeUpdates = action$.pipe( const storeUpdates = action$.pipe(
ofType(types.updateFailed), ofType(types.updateFailed),
tap(({ payload }) => { tap(({ payload = {} }) => {
if ('endpoint' in payload && 'payload' in payload) {
const failures = store.get(key) || []; const failures = store.get(key) || [];
payload.id = uuid(); payload.id = uuid();
store.set(key, [...failures, payload]); store.set(key, [...failures, payload]);
}
}), }),
map(() => onlineStatusChange(false)) map(() => onlineStatusChange(false))
); );
@ -46,7 +49,11 @@ function failedUpdateEpic(action$, { getState }) {
postUpdate$(update) postUpdate$(update)
.pipe( .pipe(
switchMap(response => { switchMap(response => {
if (response && response.message) { if (
response &&
(response.message || isGoodXHRStatus(response.status))
) {
console.info(`${update.id} succeeded`);
// the request completed successfully // the request completed successfully
const failures = store.get(key) || []; const failures = store.get(key) || [];
const newFailures = failures.filter(x => x.id !== update.id); const newFailures = failures.filter(x => x.id !== update.id);