Skip to content

Commit

Permalink
fix(requests): maintain checkRequestStatus while checking requests (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
samrum authored May 3, 2021
1 parent 314704d commit 9f24339
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Request {
private contentType: string = "application/json; charset=UTF-8";
private authRequired: boolean = true;
private upgradeRequired: boolean = true;
private checkRequestStatus: boolean | null = null;
private headers: object = {};

constructor(url: string) {
Expand Down Expand Up @@ -83,6 +84,16 @@ class Request {

return this;
}

getCheckRequestStatus(): boolean | null {
return this.checkRequestStatus;
}

setCheckRequestStatus(checkStatus: boolean | null) {
this.checkRequestStatus = checkStatus;

return this;
}
}

export default Request;
8 changes: 6 additions & 2 deletions src/RequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,10 @@ class RequestService {
const response = await this.makeClientRequest(request);
const { data } = response;

if (this.checkRequestStatus && typeof data === "object") {
const checkRequestStatus =
request.getCheckRequestStatus() ?? this.checkRequestStatus;

if (checkRequestStatus && typeof data === "object") {
const { commandResponse } = data;

if (commandResponse) {
Expand Down Expand Up @@ -371,7 +374,8 @@ class RequestService {

const request = new Request(url)
.setMethod(RequestMethod.Get)
.setUpgradeRequired(false);
.setUpgradeRequired(false)
.setCheckRequestStatus(checkRequestStatus);
return this.sendRequest(request);
}

Expand Down

0 comments on commit 9f24339

Please sign in to comment.