Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/ThumbnailApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class ThumbnailApi {

if (!this.responseHelper.okStatus(status)) {
const error = new Error(`Status ${String(status)} from upstream.`);
this.releaseUpstreamBody(remoteImageResponse);
this.sendError(expressResponse, itemId, 404, error);
return;
}
Expand All @@ -106,6 +107,7 @@ export class ThumbnailApi {

if (!this.responseHelper.okHeaders(remoteImageResponse.headers)) {
const error = new Error(`Got bad headers from upstream.`);
this.releaseUpstreamBody(remoteImageResponse);
this.sendError(expressResponse, itemId, 404, error);
return;
}
Expand Down Expand Up @@ -139,6 +141,7 @@ export class ThumbnailApi {

if (!this.responseHelper.okStatus(status)) {
const error = new Error(`Status ${String(status)} from upstream.`);
this.releaseUpstreamBody(response);
this.sendError(expressResponse, itemId, 404, error);
return;
}
Expand Down Expand Up @@ -169,6 +172,10 @@ export class ThumbnailApi {
}
}

private releaseUpstreamBody(response: Response): void {
void response.body?.cancel?.()?.catch(() => {});
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

sendError(
res: express.Response,
itemId: string,
Expand Down
Loading