Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit ac62663

Browse files
Update disable api calls logic
1 parent 06b0c9a commit ac62663

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/script/acquisition-sdk.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ export class AcquisitionStatus {
5858
}
5959

6060
export class AcquisitionManager {
61+
readonly BASER_URL = "https://codepush.appcenter.ms"
6162
private _appVersion: string;
6263
private _clientUniqueId: string;
6364
private _deploymentKey: string;
6465
private _httpRequester: Http.Requester;
6566
private _ignoreAppVersion: boolean;
6667
private _serverUrl: string;
6768
private _publicPrefixUrl: string = "v0.1/public/codepush/";
68-
private _apiAttempts: number = 0;
69+
private static _apiCallsDisabled: Boolean = false;
6970
constructor(httpRequester: Http.Requester, configuration: Configuration) {
7071
this._httpRequester = httpRequester;
7172

@@ -80,8 +81,14 @@ export class AcquisitionManager {
8081
this._ignoreAppVersion = configuration.ignoreAppVersion;
8182
}
8283

84+
private disableApiCalls(statusCode: number) {
85+
if (this._serverUrl.includes(this.BASER_URL) && !(statusCode >= 500 || statusCode == 408 || statusCode == 429)) {
86+
AcquisitionManager._apiCallsDisabled = true
87+
}
88+
}
89+
8390
public queryUpdateWithCurrentPackage(currentPackage: Package, callback?: Callback<RemotePackage | NativeUpdateNotification>): void {
84-
if(this._apiAttempts>=1) return
91+
if (AcquisitionManager._apiCallsDisabled) return
8592
if (!currentPackage || !currentPackage.appVersion) {
8693
throw new CodePushPackageError("Calling common acquisition SDK with incorrect package"); // Unexpected; indicates error in our implementation
8794
}
@@ -105,7 +112,7 @@ export class AcquisitionManager {
105112

106113
if (response.statusCode !== 200) {
107114
let errorMessage: any;
108-
this._apiAttempts++
115+
this.disableApiCalls(response.statusCode)
109116
if (response.statusCode === 0) {
110117
errorMessage = `Couldn't send request to ${requestUrl}, xhr.statusCode = 0 was returned. One of the possible reasons for that might be connection problems. Please, check your internet connection.`;
111118
} else {
@@ -149,7 +156,7 @@ export class AcquisitionManager {
149156
}
150157

151158
public reportStatusDeploy(deployedPackage?: Package, status?: string, previousLabelOrAppVersion?: string, previousDeploymentKey?: string, callback?: Callback<void>): void {
152-
if(this._apiAttempts>=1) return
159+
if (AcquisitionManager._apiCallsDisabled) return
153160
var url: string = this._serverUrl + this._publicPrefixUrl + "report_status/deploy";
154161
var body: DeploymentStatusReport = {
155162
app_version: this._appVersion,
@@ -200,7 +207,7 @@ export class AcquisitionManager {
200207
}
201208

202209
if (response.statusCode !== 200) {
203-
this._apiAttempts++
210+
this.disableApiCalls(response.statusCode)
204211
callback(new CodePushHttpError(response.statusCode + ": " + response.body), /*not used*/ null);
205212
return;
206213
}
@@ -211,7 +218,7 @@ export class AcquisitionManager {
211218
}
212219

213220
public reportStatusDownload(downloadedPackage: Package, callback?: Callback<void>): void {
214-
if(this._apiAttempts>=1) return
221+
if (AcquisitionManager._apiCallsDisabled) return
215222
var url: string = this._serverUrl + this._publicPrefixUrl + "report_status/download";
216223
var body: DownloadReport = {
217224
client_unique_id: this._clientUniqueId,
@@ -227,7 +234,7 @@ export class AcquisitionManager {
227234
}
228235

229236
if (response.statusCode !== 200) {
230-
this._apiAttempts++
237+
this.disableApiCalls(response.statusCode)
231238
callback(new CodePushHttpError(response.statusCode + ": " + response.body), /*not used*/ null);
232239
return;
233240
}

0 commit comments

Comments
 (0)