Skip to content

Commit

Permalink
Fix typo and refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
DordeDimitrijev committed Dec 6, 2024
1 parent 05fb0d4 commit 9204133
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/script/acquisition-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ export class AcquisitionStatus {
}

export class AcquisitionManager {
private readonly BASER_URL_PART = "appcenter.ms";
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;
Expand All @@ -82,9 +82,10 @@ export class AcquisitionManager {
this._ignoreAppVersion = configuration.ignoreAppVersion;
}

private isRecoverable = (statusCode: number): boolean => statusCode >= 500 || statusCode === 408 || statusCode === 429;

private handleRequestFailure(statusCode: number) {
if (this._serverUrl.includes(this.BASER_URL_PART) && !(statusCode >= 500 || statusCode == 408 || statusCode == 429)) {
private handleRequestFailure() {
if (this._serverUrl.includes(this.BASE_URL_PART) && !this.isRecoverable(this._statusCode)) {
AcquisitionManager._apiCallsDisabled = true;
}
}
Expand Down Expand Up @@ -119,7 +120,8 @@ export class AcquisitionManager {

if (response.statusCode !== 200) {
let errorMessage: any;
this.handleRequestFailure(response.statusCode)
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 {
Expand Down Expand Up @@ -219,7 +221,8 @@ export class AcquisitionManager {
}

if (response.statusCode !== 200) {
this.handleRequestFailure(response.statusCode)
this._statusCode = response.statusCode;
this.handleRequestFailure();
callback(new CodePushHttpError(response.statusCode + ": " + response.body), /*not used*/ null);
return;
}
Expand Down Expand Up @@ -251,7 +254,8 @@ export class AcquisitionManager {
}

if (response.statusCode !== 200) {
this.handleRequestFailure(response.statusCode)
this._statusCode = response.statusCode;
this.handleRequestFailure();
callback(new CodePushHttpError(response.statusCode + ": " + response.body), /*not used*/ null);
return;
}
Expand Down

0 comments on commit 9204133

Please sign in to comment.