Skip to content

Commit 862acd7

Browse files
committed
Don't resolve createUploadRequest too soon
1 parent 5413698 commit 862acd7

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/index.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,20 +228,19 @@ async function createUploadRequest(
228228

229229
// Send the headers now. If the server would reject this request, it should
230230
// do so asap. This prevents us from sending more data to it then necessary.
231-
// If it will reject we could just await the `req.on(response` now but if it
232-
// accepts the request then the response will not come until after the final
233-
// file. So we can't await the response at this time. Just proceed, carefully.
231+
// If it will reject we could just await the `req.on(response, ...` now but
232+
// if it accepts the request then the response will not come until after the
233+
// final file. So we can't await the response at this time. Just proceed,
234+
// carefully.
234235
req.flushHeaders()
235236

236237
// Wait for the response. It may arrive at any point during the request or
237238
// afterwards. Node will flush the output buffer at some point, initiating
238239
// the request, and the server can decide to reject the request immediately
239240
// or at any point later (ike a timeout). We should handle those cases.
240241
getResponse(req).then(
241-
res => {
242-
// Note: this returns the response to the caller to createUploadRequest
243-
pass(res)
244-
},
242+
// Note: this returns the response to the caller to createUploadRequest.
243+
pass,
245244
async err => {
246245
// Note: this will throw an error for the caller to createUploadRequest
247246
if (err.response && !isResponseOk(err.response)) {
@@ -305,8 +304,6 @@ async function createUploadRequest(
305304
req.end()
306305
}
307306
}
308-
309-
pass(getResponse(req))
310307
})
311308
}
312309

0 commit comments

Comments
 (0)