This repository was archived by the owner on May 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 524
Disable api calls #851
Merged
Merged
Disable api calls #851
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
06b0c9a
Stop sending api calls after unsuccessful request
DordeDimitrijev ac62663
Update disable api calls logic
DordeDimitrijev 8edb766
Update access modifer
DordeDimitrijev deffe54
Add test case for disabling api calls
DordeDimitrijev c3e1c78
Reformat code
DordeDimitrijev 9baedae
Refactor and reformat code
DordeDimitrijev 315ba25
Improve tests
DordeDimitrijev b9a7352
Update unit tests
DordeDimitrijev b89d036
Update test cases
DordeDimitrijev d0cfdd2
Remove static getter
DordeDimitrijev 05fb0d4
Reformat code
DordeDimitrijev 9204133
Fix typo and refactor code
DordeDimitrijev e151119
Handle all non 2xx status codes
DordeDimitrijev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,14 +58,16 @@ export class AcquisitionStatus { | |
} | ||
|
||
export class AcquisitionManager { | ||
private readonly BASE_URL_PART = "appcenter.ms"; | ||
private _appVersion: string; | ||
private _clientUniqueId: string; | ||
private _deploymentKey: string; | ||
private _httpRequester: Http.Requester; | ||
private _ignoreAppVersion: boolean; | ||
private _serverUrl: string; | ||
private _publicPrefixUrl: string = "v0.1/public/codepush/"; | ||
|
||
private _statusCode: number; | ||
private static _apiCallsDisabled: boolean = false; | ||
constructor(httpRequester: Http.Requester, configuration: Configuration) { | ||
this._httpRequester = httpRequester; | ||
|
||
|
@@ -80,7 +82,21 @@ export class AcquisitionManager { | |
this._ignoreAppVersion = configuration.ignoreAppVersion; | ||
} | ||
|
||
private isRecoverable = (statusCode: number): boolean => statusCode >= 500 || statusCode === 408 || statusCode === 429; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You check this when response code is not 200 - what about other 2xx or 3xx responses - are they recoverable or not? |
||
|
||
private handleRequestFailure() { | ||
if (this._serverUrl.includes(this.BASE_URL_PART) && !this.isRecoverable(this._statusCode)) { | ||
AcquisitionManager._apiCallsDisabled = true; | ||
} | ||
} | ||
|
||
public queryUpdateWithCurrentPackage(currentPackage: Package, callback?: Callback<RemotePackage | NativeUpdateNotification>): void { | ||
if (AcquisitionManager._apiCallsDisabled) { | ||
console.log(`[CodePush] Api calls are disabled, skipping API call`); | ||
callback(/*error=*/ null, /*remotePackage=*/ null); | ||
return; | ||
} | ||
|
||
if (!currentPackage || !currentPackage.appVersion) { | ||
throw new CodePushPackageError("Calling common acquisition SDK with incorrect package"); // Unexpected; indicates error in our implementation | ||
} | ||
|
@@ -102,8 +118,10 @@ export class AcquisitionManager { | |
return; | ||
} | ||
|
||
if (response.statusCode !== 200) { | ||
if (response.statusCode < 200 || response.statusCode >= 300) { | ||
let errorMessage: any; | ||
this._statusCode = response.statusCode; | ||
this.handleRequestFailure(); | ||
if (response.statusCode === 0) { | ||
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.`; | ||
} else { | ||
|
@@ -147,6 +165,12 @@ export class AcquisitionManager { | |
} | ||
|
||
public reportStatusDeploy(deployedPackage?: Package, status?: string, previousLabelOrAppVersion?: string, previousDeploymentKey?: string, callback?: Callback<void>): void { | ||
if (AcquisitionManager._apiCallsDisabled) { | ||
console.log(`[CodePush] Api calls are disabled, skipping API call`); | ||
callback(/*error*/ null, /*not used*/ null); | ||
return; | ||
DmitriyKirakosyan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
var url: string = this._serverUrl + this._publicPrefixUrl + "report_status/deploy"; | ||
var body: DeploymentStatusReport = { | ||
app_version: this._appVersion, | ||
|
@@ -196,7 +220,9 @@ export class AcquisitionManager { | |
return; | ||
} | ||
|
||
if (response.statusCode !== 200) { | ||
if (response.statusCode < 200 || response.statusCode >= 300) { | ||
this._statusCode = response.statusCode; | ||
this.handleRequestFailure(); | ||
callback(new CodePushHttpError(response.statusCode + ": " + response.body), /*not used*/ null); | ||
return; | ||
} | ||
|
@@ -207,6 +233,12 @@ export class AcquisitionManager { | |
} | ||
|
||
public reportStatusDownload(downloadedPackage: Package, callback?: Callback<void>): void { | ||
if (AcquisitionManager._apiCallsDisabled) { | ||
console.log(`[CodePush] Api calls are disabled, skipping API call`); | ||
callback(/*error*/ null, /*not used*/ null); | ||
return; | ||
} | ||
|
||
var url: string = this._serverUrl + this._publicPrefixUrl + "report_status/download"; | ||
var body: DownloadReport = { | ||
client_unique_id: this._clientUniqueId, | ||
|
@@ -221,7 +253,9 @@ export class AcquisitionManager { | |
return; | ||
} | ||
|
||
if (response.statusCode !== 200) { | ||
if (response.statusCode < 200 || response.statusCode >= 300) { | ||
this._statusCode = response.statusCode; | ||
this.handleRequestFailure(); | ||
callback(new CodePushHttpError(response.statusCode + ": " + response.body), /*not used*/ null); | ||
return; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.