Skip to content

Commit

Permalink
apply failureData for fetch failures
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Sep 21, 2023
1 parent 2d03318 commit fbaaac8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
9 changes: 0 additions & 9 deletions src/libs/HttpUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ONYXKEYS from '../ONYXKEYS';
import HttpsError from './Errors/HttpsError';
import * as ApiUtils from './ApiUtils';
import alert from '../components/Alert';
import Log from './Log';

let shouldFailAllRequests = false;
let shouldForceOffline = false;
Expand Down Expand Up @@ -106,14 +105,6 @@ function processHTTPRequest(url, method = 'get', body = null, canCancel = true)
}
return response;
})
.catch(() => {
if (method !== 'get') {
return;
}

Log.hmmm(`READ request failed to fetch ${url}. Resolving promise to apply Onyx failure data`);
return Promise.resolve({});
});
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/libs/Request.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Onyx from 'react-native-onyx';
import HttpUtils from './HttpUtils';
import enhanceParameters from './Network/enhanceParameters';
import * as NetworkStore from './Network/NetworkStore';
Expand All @@ -20,7 +21,12 @@ function makeXHR(request: Request): Promise<unknown> {
}

function processWithMiddleware(request: Request, isFromSequentialQueue = false): Promise<unknown> {
return middlewares.reduce((last, middleware) => middleware(last, request, isFromSequentialQueue), makeXHR(request));
return middlewares.reduce((last, middleware) => middleware(last, request, isFromSequentialQueue), makeXHR(request).catch(() => {
if (!request.failureData) {
return;
}
Onyx.update(request.failureData);
}));
}

function use(middleware: Middleware) {
Expand Down

0 comments on commit fbaaac8

Please sign in to comment.