Skip to content

Commit 8fe6367

Browse files
committed
Add more .end() calls
1 parent 1bbd709 commit 8fe6367

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/index.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,24 @@ async function createUploadRequest(
161161
'Content-Type': `multipart/form-data; boundary=${boundary}`
162162
}
163163
})
164-
// Send the request body (headers + files).
165-
for (const part of requestBody) {
166-
if (typeof part === 'string') {
167-
req.write(part)
168-
} else {
169-
part.pipe(req, { end: false })
170-
// Wait for file streaming to complete.
171-
// eslint-disable-next-line no-await-in-loop
172-
await events.once(part, 'end')
173-
// Ensure a new line after file content.
174-
req.write('\n')
164+
try {
165+
// Send the request body (headers + files).
166+
for (const part of requestBody) {
167+
if (typeof part === 'string') {
168+
req.write(part)
169+
} else {
170+
part.pipe(req, { end: false })
171+
// Wait for file streaming to complete.
172+
// eslint-disable-next-line no-await-in-loop
173+
await events.once(part, 'end')
174+
// Ensure a new line after file content.
175+
req.write('\n')
176+
}
175177
}
178+
} finally {
179+
// Close request after writing all data.
180+
req.end()
176181
}
177-
// Close request after writing all data.
178-
req.end()
179182
return await getResponse(req)
180183
}
181184

@@ -647,13 +650,15 @@ export class SocketSdk {
647650
file?: string
648651
): Promise<SocketSdkResultType<'getOrgFullScan'>> {
649652
try {
650-
const req = https.request(
651-
`${this.#baseUrl}orgs/${encodeURIComponent(orgSlug)}/full-scans/${encodeURIComponent(fullScanId)}`,
652-
{
653-
method: 'GET',
654-
...this.#reqOptions
655-
}
656-
)
653+
const req = https
654+
.request(
655+
`${this.#baseUrl}orgs/${encodeURIComponent(orgSlug)}/full-scans/${encodeURIComponent(fullScanId)}`,
656+
{
657+
method: 'GET',
658+
...this.#reqOptions
659+
}
660+
)
661+
.end()
657662
const res = await getResponse(req)
658663
if (file) {
659664
res.pipe(createWriteStream(file))

0 commit comments

Comments
 (0)