fix(response handling): Handle success responses better
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
b7aee9928e
commit
ca70573bd8
@ -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);
|
||||||
|
Reference in New Issue
Block a user