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

Commit 06b0c9a

Browse files
Stop sending api calls after unsuccessful request
1 parent 682b9f2 commit 06b0c9a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/script/acquisition-sdk.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class AcquisitionManager {
6565
private _ignoreAppVersion: boolean;
6666
private _serverUrl: string;
6767
private _publicPrefixUrl: string = "v0.1/public/codepush/";
68-
68+
private _apiAttempts: number = 0;
6969
constructor(httpRequester: Http.Requester, configuration: Configuration) {
7070
this._httpRequester = httpRequester;
7171

@@ -81,6 +81,7 @@ export class AcquisitionManager {
8181
}
8282

8383
public queryUpdateWithCurrentPackage(currentPackage: Package, callback?: Callback<RemotePackage | NativeUpdateNotification>): void {
84+
if(this._apiAttempts>=1) return
8485
if (!currentPackage || !currentPackage.appVersion) {
8586
throw new CodePushPackageError("Calling common acquisition SDK with incorrect package"); // Unexpected; indicates error in our implementation
8687
}
@@ -104,6 +105,7 @@ export class AcquisitionManager {
104105

105106
if (response.statusCode !== 200) {
106107
let errorMessage: any;
108+
this._apiAttempts++
107109
if (response.statusCode === 0) {
108110
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.`;
109111
} else {
@@ -147,6 +149,7 @@ export class AcquisitionManager {
147149
}
148150

149151
public reportStatusDeploy(deployedPackage?: Package, status?: string, previousLabelOrAppVersion?: string, previousDeploymentKey?: string, callback?: Callback<void>): void {
152+
if(this._apiAttempts>=1) return
150153
var url: string = this._serverUrl + this._publicPrefixUrl + "report_status/deploy";
151154
var body: DeploymentStatusReport = {
152155
app_version: this._appVersion,
@@ -197,6 +200,7 @@ export class AcquisitionManager {
197200
}
198201

199202
if (response.statusCode !== 200) {
203+
this._apiAttempts++
200204
callback(new CodePushHttpError(response.statusCode + ": " + response.body), /*not used*/ null);
201205
return;
202206
}
@@ -207,6 +211,7 @@ export class AcquisitionManager {
207211
}
208212

209213
public reportStatusDownload(downloadedPackage: Package, callback?: Callback<void>): void {
214+
if(this._apiAttempts>=1) return
210215
var url: string = this._serverUrl + this._publicPrefixUrl + "report_status/download";
211216
var body: DownloadReport = {
212217
client_unique_id: this._clientUniqueId,
@@ -222,10 +227,11 @@ export class AcquisitionManager {
222227
}
223228

224229
if (response.statusCode !== 200) {
230+
this._apiAttempts++
225231
callback(new CodePushHttpError(response.statusCode + ": " + response.body), /*not used*/ null);
226232
return;
227233
}
228-
234+
229235
callback(/*error*/ null, /*not used*/ null);
230236
}
231237
});

0 commit comments

Comments
 (0)