Skip to content

Commit

Permalink
Fixed: Cannot read properties of undefined (reading 'push') (#8648)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev authored Nov 7, 2024
1 parent 148a572 commit ac20ed2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20241106_095739_sekachev.bs_fixed_exception_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Fixed issue 'Cannot read properties of undefined (reading 'push')'
(<https://github.com/cvat-ai/cvat/pull/8648>)
33 changes: 18 additions & 15 deletions cvat-core/src/requests-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RequestsManager {
requestDelayIdx: number | null,
request: Request | null,
timeout: number | null;
promise?: Promise<Request>;
promise: Promise<Request>;
}>;

private requestStack: number[];
Expand Down Expand Up @@ -71,6 +71,7 @@ class RequestsManager {
}
return this.listening[requestID].promise;
}

const promise = new Promise<Request>((resolve, reject) => {
const timeoutCallback = async (): Promise<void> => {
// We make sure that no more than REQUESTS_COUNT requests are sent simultaneously
Expand Down Expand Up @@ -131,27 +132,29 @@ class RequestsManager {
message: `Could not get a status of the request ${requestID}. ${error.toString()}`,
})));
}

delete this.listening[requestID];
reject(error);
}
}
};

if (initialRequest?.status === RQStatus.FAILED) {
reject(new RequestError(initialRequest?.message));
} else {
this.listening[requestID] = {
onUpdate: callback ? [callback] : [],
timeout: window.setTimeout(timeoutCallback),
request: initialRequest,
requestDelayIdx: 0,
};
}
Promise.resolve().then(() => {
// running as microtask to make sure "promise" was initialized
if (initialRequest?.status === RQStatus.FAILED) {
reject(new RequestError(initialRequest?.message));
} else {
this.listening[requestID] = {
onUpdate: callback ? [callback] : [],
timeout: window.setTimeout(timeoutCallback),
request: initialRequest,
requestDelayIdx: 0,
promise,
};
}
});
});

this.listening[requestID] = {
...this.listening[requestID],
promise,
};
return promise;
}

Expand Down

0 comments on commit ac20ed2

Please sign in to comment.