@@ -22,7 +22,7 @@ test('properties', withServer, async (t, server, got) => {
22
22
23
23
const url = new URL ( server . url ) ;
24
24
25
- const error = await t . throwsAsync < HTTPError > ( got ( '' ) ) ;
25
+ const error = ( await t . throwsAsync < HTTPError > ( got ( '' ) ) ) ! ;
26
26
t . truthy ( error ) ;
27
27
t . truthy ( error . response ) ;
28
28
t . truthy ( error . options ) ;
@@ -36,7 +36,7 @@ test('properties', withServer, async (t, server, got) => {
36
36
} ) ;
37
37
38
38
test ( 'catches dns errors' , async t => {
39
- const error = await t . throwsAsync < RequestError > ( got ( 'http://doesntexist' , { retry : { limit : 0 } } ) ) ;
39
+ const error = ( await t . throwsAsync < RequestError > ( got ( 'http://doesntexist' , { retry : { limit : 0 } } ) ) ) ! ;
40
40
t . truthy ( error ) ;
41
41
t . regex ( error . message , / E N O T F O U N D | E A I _ A G A I N / ) ;
42
42
t . is ( ( error . options . url as URL ) . host , 'doesntexist' ) ;
@@ -80,8 +80,8 @@ test('default status message', withServer, async (t, server, got) => {
80
80
instanceOf : HTTPError ,
81
81
message : 'Response code 400 (Bad Request)' ,
82
82
} ) ;
83
- t . is ( error . response . statusCode , 400 ) ;
84
- t . is ( error . response . statusMessage , 'Bad Request' ) ;
83
+ t . is ( error ? .response . statusCode , 400 ) ;
84
+ t . is ( error ? .response . statusMessage , 'Bad Request' ) ;
85
85
} ) ;
86
86
87
87
test ( 'custom status message' , withServer , async ( t , server , got ) => {
@@ -96,8 +96,8 @@ test('custom status message', withServer, async (t, server, got) => {
96
96
instanceOf : HTTPError ,
97
97
message : 'Response code 400 (Something Exploded)' ,
98
98
} ) ;
99
- t . is ( error . response . statusCode , 400 ) ;
100
- t . is ( error . response . statusMessage , 'Something Exploded' ) ;
99
+ t . is ( error ? .response . statusCode , 400 ) ;
100
+ t . is ( error ? .response . statusMessage , 'Something Exploded' ) ;
101
101
} ) ;
102
102
103
103
test ( 'custom body' , withServer , async ( t , server , got ) => {
@@ -111,8 +111,8 @@ test('custom body', withServer, async (t, server, got) => {
111
111
instanceOf : HTTPError ,
112
112
message : 'Response code 404 (Not Found)' ,
113
113
} ) ;
114
- t . is ( error . response . statusCode , 404 ) ;
115
- t . is ( error . response . body , 'not' ) ;
114
+ t . is ( error ? .response . statusCode , 404 ) ;
115
+ t . is ( error ? .response . body , 'not' ) ;
116
116
} ) ;
117
117
118
118
test ( 'contains Got options' , withServer , async ( t , server , got ) => {
@@ -132,8 +132,8 @@ test('contains Got options', withServer, async (t, server, got) => {
132
132
instanceOf : HTTPError ,
133
133
message : 'Response code 404 (Not Found)' ,
134
134
} ) ;
135
- t . is ( error . response . statusCode , 404 ) ;
136
- t . is ( error . options . context . foo , options . context . foo ) ;
135
+ t . is ( error ? .response . statusCode , 404 ) ;
136
+ t . is ( error ? .options . context . foo , options . context . foo ) ;
137
137
} ) ;
138
138
139
139
test ( 'empty status message is overriden by the default one' , withServer , async ( t , server , got ) => {
@@ -147,8 +147,8 @@ test('empty status message is overriden by the default one', withServer, async (
147
147
instanceOf : HTTPError ,
148
148
message : 'Response code 400 (Bad Request)' ,
149
149
} ) ;
150
- t . is ( error . response . statusCode , 400 ) ;
151
- t . is ( error . response . statusMessage , http . STATUS_CODES [ 400 ] ) ;
150
+ t . is ( error ? .response . statusCode , 400 ) ;
151
+ t . is ( error ? .response . statusMessage , http . STATUS_CODES [ 400 ] ) ;
152
152
} ) ;
153
153
154
154
test ( '`http.request` error' , async t => {
@@ -227,17 +227,17 @@ test('normalization errors using convenience methods', async t => {
227
227
228
228
{
229
229
const error = await t . throwsAsync ( got ( url ) . json ( ) ) ;
230
- invalidUrl ( t , error , url ) ;
230
+ invalidUrl ( t , error ! , url ) ;
231
231
}
232
232
233
233
{
234
234
const error = await t . throwsAsync ( got ( url ) . text ( ) ) ;
235
- invalidUrl ( t , error , url ) ;
235
+ invalidUrl ( t , error ! , url ) ;
236
236
}
237
237
238
238
{
239
239
const error = await t . throwsAsync ( got ( url ) . buffer ( ) ) ;
240
- invalidUrl ( t , error , url ) ;
240
+ invalidUrl ( t , error ! , url ) ;
241
241
}
242
242
} ) ;
243
243
@@ -249,8 +249,8 @@ test('errors can have request property', withServer, async (t, server, got) => {
249
249
250
250
const error = await t . throwsAsync < HTTPError > ( got ( '' ) ) ;
251
251
252
- t . truthy ( error . response ) ;
253
- t . truthy ( error . request . downloadProgress ) ;
252
+ t . truthy ( error ? .response ) ;
253
+ t . truthy ( error ? .request . downloadProgress ) ;
254
254
} ) ;
255
255
256
256
test ( 'promise does not hang on timeout on HTTP error' , withServer , async ( t , server , got ) => {
@@ -333,11 +333,11 @@ test.skip('the old stacktrace is recovered', async t => {
333
333
} ,
334
334
} ) ) ;
335
335
336
- t . true ( error . stack ! . includes ( 'at Object.request' ) ) ;
336
+ t . true ( error ? .stack ! . includes ( 'at Object.request' ) ) ;
337
337
338
338
// The first `at get` points to where the error was wrapped,
339
339
// the second `at get` points to the real cause.
340
- t . not ( error . stack ! . indexOf ( 'at get' ) , error . stack ! . lastIndexOf ( 'at get' ) ) ;
340
+ t . not ( error ? .stack ! . indexOf ( 'at get' ) , error ? .stack ! . lastIndexOf ( 'at get' ) ) ;
341
341
} ) ;
342
342
343
343
test . serial ( 'custom stack trace' , withServer , async ( t , _server , got ) => {
@@ -363,7 +363,7 @@ test.serial('custom stack trace', withServer, async (t, _server, got) => {
363
363
stream . destroy ( new Error ( 'oh no' ) ) ;
364
364
365
365
const caught = await t . throwsAsync ( getStream ( stream ) ) ;
366
- t . is ( is ( caught . stack ) , 'string' ) ;
366
+ t . is ( is ( caught ? .stack ) , 'string' ) ;
367
367
}
368
368
369
369
// Passing a custom error
@@ -376,7 +376,7 @@ test.serial('custom stack trace', withServer, async (t, _server, got) => {
376
376
stream . destroy ( error ) ;
377
377
378
378
const caught = await t . throwsAsync ( getStream ( stream ) ) ;
379
- t . is ( is ( caught . stack ) , 'string' ) ;
379
+ t . is ( is ( caught ? .stack ) , 'string' ) ;
380
380
}
381
381
382
382
// Custom global behavior
@@ -388,7 +388,7 @@ test.serial('custom stack trace', withServer, async (t, _server, got) => {
388
388
stream . destroy ( error ) ;
389
389
390
390
const caught = await t . throwsAsync ( getStream ( stream ) ) ;
391
- t . is ( is ( caught . stack ) , 'Array' ) ;
391
+ t . is ( is ( caught ? .stack ) , 'Array' ) ;
392
392
393
393
disable ( ) ;
394
394
}
@@ -402,7 +402,7 @@ test.serial('custom stack trace', withServer, async (t, _server, got) => {
402
402
stream . destroy ( error ) ;
403
403
404
404
const caught = await t . throwsAsync ( getStream ( stream ) ) ;
405
- t . is ( is ( caught . stack ) , 'Array' ) ;
405
+ t . is ( is ( caught ? .stack ) , 'Array' ) ;
406
406
407
407
disable ( ) ;
408
408
}
0 commit comments