File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -1426,17 +1426,25 @@ export default class Request extends Duplex implements RequestEvents<Request> {
1426
1426
this . _lockWrite ( ) ;
1427
1427
}
1428
1428
1429
- ( async ( nonNormalizedOptions : Options ) => {
1429
+ if ( kIsNormalizedAlready in options ) {
1430
+ this . options = options as NormalizedOptions ;
1431
+ } else {
1430
1432
try {
1431
- if ( nonNormalizedOptions . body instanceof ReadStream ) {
1432
- await waitForOpenFile ( nonNormalizedOptions . body ) ;
1433
+ // @ts -expect-error Common TypeScript bug saying that `this.constructor` is not accessible
1434
+ this . options = this . constructor . normalizeArguments ( url , options , defaults ) ;
1435
+ } catch ( error ) {
1436
+ if ( is . nodeStream ( options . body ) ) {
1437
+ options . body . destroy ( ) ;
1433
1438
}
1434
1439
1435
- if ( kIsNormalizedAlready in nonNormalizedOptions ) {
1436
- this . options = nonNormalizedOptions as NormalizedOptions ;
1437
- } else {
1438
- // @ts -expect-error Common TypeScript bug saying that `this.constructor` is not accessible
1439
- this . options = this . constructor . normalizeArguments ( url , nonNormalizedOptions , defaults ) ;
1440
+ throw error ;
1441
+ }
1442
+ }
1443
+
1444
+ ( async ( ) => {
1445
+ try {
1446
+ if ( this . options . body instanceof ReadStream ) {
1447
+ await waitForOpenFile ( this . options . body ) ;
1440
1448
}
1441
1449
1442
1450
const { url : normalizedURL } = this . options ;
@@ -1476,7 +1484,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
1476
1484
this . destroy ( error ) ;
1477
1485
}
1478
1486
}
1479
- } ) ( options ) ;
1487
+ } ) ( ) ;
1480
1488
}
1481
1489
1482
1490
static normalizeArguments ( url ?: string | URL , options ?: Options , defaults ?: Defaults ) : NormalizedOptions {
Original file line number Diff line number Diff line change @@ -328,7 +328,7 @@ test.failing('no unhandled body stream errors', async t => {
328
328
body . append ( 'upload' , fs . createReadStream ( '/bin/sh' ) ) ;
329
329
330
330
await t . throwsAsync ( got . post ( `https://offlinesite${ Date . now ( ) } .com` , {
331
- form : body
331
+ body
332
332
} ) , {
333
333
code : 'ENOTFOUND'
334
334
} ) ;
You can’t perform that action at this time.
0 commit comments