From fbaaac8ebe17b6617dbc0aeb05d2db2cdb08b1e0 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 21 Sep 2023 17:12:35 +0800 Subject: [PATCH] apply failureData for fetch failures --- src/libs/HttpUtils.js | 9 --------- src/libs/Request.ts | 8 +++++++- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/libs/HttpUtils.js b/src/libs/HttpUtils.js index dcfa3412566d..d7e389a45ccc 100644 --- a/src/libs/HttpUtils.js +++ b/src/libs/HttpUtils.js @@ -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; @@ -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({}); - }); } /** diff --git a/src/libs/Request.ts b/src/libs/Request.ts index 459deaf89e1e..c8a3c869f3c9 100644 --- a/src/libs/Request.ts +++ b/src/libs/Request.ts @@ -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'; @@ -20,7 +21,12 @@ function makeXHR(request: Request): Promise { } function processWithMiddleware(request: Request, isFromSequentialQueue = false): Promise { - 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) {