Skip to content

Commit

Permalink
Final API refactors, use const commands
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejkustra committed Jan 23, 2024
1 parent bc873ab commit 8444a4d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/libs/HttpUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type {RequestType} from '@src/types/onyx/Request';
import type Response from '@src/types/onyx/Response';
import * as NetworkActions from './actions/Network';
import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS} from './API/types';
import * as ApiUtils from './ApiUtils';
import HttpsError from './Errors/HttpsError';

Expand All @@ -29,7 +30,7 @@ let cancellationController = new AbortController();
/**
* The API commands that require the skew calculation
*/
const addSkewList = ['OpenReport', 'ReconnectApp', 'OpenApp'];
const addSkewList: string[] = [SIDE_EFFECT_REQUEST_COMMANDS.OPEN_REPORT, SIDE_EFFECT_REQUEST_COMMANDS.RECONNECT_APP, READ_COMMANDS.OPEN_APP];

/**
* Regex to get API command from the command
Expand Down
3 changes: 2 additions & 1 deletion src/libs/Middleware/Logging.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {SIDE_EFFECT_REQUEST_COMMANDS} from '@libs/API/types';
import Log from '@libs/Log';
import CONST from '@src/CONST';
import type Request from '@src/types/onyx/Request';
Expand Down Expand Up @@ -87,7 +88,7 @@ const Logging: Middleware = (response, request) => {
// This error seems to only throw on dev when localhost:8080 tries to access the production web server. It's unclear whether this can happen on production or if
// it's a sign that the web server is down.
Log.hmmm('[Network] API request error: Gateway Timeout error', logParams);
} else if (request.command === 'AuthenticatePusher') {
} else if (request.command === SIDE_EFFECT_REQUEST_COMMANDS.AUTHENTICATE_PUSHER) {
// AuthenticatePusher requests can return with fetch errors and no message. It happens because we return a non 200 header like 403 Forbidden.
// This is common to see if we are subscribing to a bad channel related to something the user shouldn't be able to access. There's no additional information
// we can get about these requests.
Expand Down
3 changes: 2 additions & 1 deletion src/libs/Middleware/SaveResponseInOnyx.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS} from '@libs/API/types';
import * as MemoryOnlyKeys from '@userActions/MemoryOnlyKeys/MemoryOnlyKeys';
import * as OnyxUpdates from '@userActions/OnyxUpdates';
import CONST from '@src/CONST';
Expand All @@ -6,7 +7,7 @@ import type Middleware from './types';

// If we're executing any of these requests, we don't need to trigger our OnyxUpdates flow to update the current data even if our current value is out of
// date because all these requests are updating the app to the most current state.
const requestsToIgnoreLastUpdateID = ['OpenApp', 'ReconnectApp', 'GetMissingOnyxMessages'];
const requestsToIgnoreLastUpdateID = [READ_COMMANDS.OPEN_APP, SIDE_EFFECT_REQUEST_COMMANDS.RECONNECT_APP, SIDE_EFFECT_REQUEST_COMMANDS.GET_MISSING_ONYX_MESSAGES];

const SaveResponseInOnyx: Middleware = (requestResponse, request) =>
requestResponse.then((response = {}) => {
Expand Down
3 changes: 2 additions & 1 deletion src/libs/Network/NetworkStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Onyx from 'react-native-onyx';
import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS} from '@libs/API/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type Credentials from '@src/types/onyx/Credentials';

Expand Down Expand Up @@ -95,7 +96,7 @@ function getAuthToken(): string | null {
}

function isSupportRequest(command: string): boolean {
return ['OpenApp', 'ReconnectApp', 'OpenReport'].includes(command);
return [READ_COMMANDS.OPEN_APP, SIDE_EFFECT_REQUEST_COMMANDS.RECONNECT_APP, SIDE_EFFECT_REQUEST_COMMANDS.OPEN_REPORT].some((cmd) => cmd === command);
}

function getSupportAuthToken(): string | null {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ function setAccountError(error: string) {
const reauthenticatePusher = throttle(
() => {
Log.info('[Pusher] Re-authenticating and then reconnecting');
Authentication.reauthenticate('AuthenticatePusher')
Authentication.reauthenticate(SIDE_EFFECT_REQUEST_COMMANDS.AUTHENTICATE_PUSHER)
.then(Pusher.reconnect)
.catch(() => {
console.debug('[PusherConnectionManager]', 'Unable to re-authenticate Pusher because we are offline.');
Expand Down

0 comments on commit 8444a4d

Please sign in to comment.