@@ -22,7 +22,7 @@ test('properties', withServer, async (t, server, got) => {
2222
2323 const url = new URL ( server . url ) ;
2424
25- const error = await t . throwsAsync < HTTPError > ( got ( '' ) ) ;
25+ const error = ( await t . throwsAsync < HTTPError > ( got ( '' ) ) ) ! ;
2626 t . truthy ( error ) ;
2727 t . truthy ( error . response ) ;
2828 t . truthy ( error . options ) ;
@@ -36,7 +36,7 @@ test('properties', withServer, async (t, server, got) => {
3636} ) ;
3737
3838test ( '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 } } ) ) ) ! ;
4040 t . truthy ( error ) ;
4141 t . regex ( error . message , / E N O T F O U N D | E A I _ A G A I N / ) ;
4242 t . is ( ( error . options . url as URL ) . host , 'doesntexist' ) ;
@@ -80,8 +80,8 @@ test('default status message', withServer, async (t, server, got) => {
8080 instanceOf : HTTPError ,
8181 message : 'Response code 400 (Bad Request)' ,
8282 } ) ;
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' ) ;
8585} ) ;
8686
8787test ( 'custom status message' , withServer , async ( t , server , got ) => {
@@ -96,8 +96,8 @@ test('custom status message', withServer, async (t, server, got) => {
9696 instanceOf : HTTPError ,
9797 message : 'Response code 400 (Something Exploded)' ,
9898 } ) ;
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' ) ;
101101} ) ;
102102
103103test ( 'custom body' , withServer , async ( t , server , got ) => {
@@ -111,8 +111,8 @@ test('custom body', withServer, async (t, server, got) => {
111111 instanceOf : HTTPError ,
112112 message : 'Response code 404 (Not Found)' ,
113113 } ) ;
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' ) ;
116116} ) ;
117117
118118test ( 'contains Got options' , withServer , async ( t , server , got ) => {
@@ -132,8 +132,8 @@ test('contains Got options', withServer, async (t, server, got) => {
132132 instanceOf : HTTPError ,
133133 message : 'Response code 404 (Not Found)' ,
134134 } ) ;
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 ) ;
137137} ) ;
138138
139139test ( '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 (
147147 instanceOf : HTTPError ,
148148 message : 'Response code 400 (Bad Request)' ,
149149 } ) ;
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 ] ) ;
152152} ) ;
153153
154154test ( '`http.request` error' , async t => {
@@ -227,17 +227,17 @@ test('normalization errors using convenience methods', async t => {
227227
228228 {
229229 const error = await t . throwsAsync ( got ( url ) . json ( ) ) ;
230- invalidUrl ( t , error , url ) ;
230+ invalidUrl ( t , error ! , url ) ;
231231 }
232232
233233 {
234234 const error = await t . throwsAsync ( got ( url ) . text ( ) ) ;
235- invalidUrl ( t , error , url ) ;
235+ invalidUrl ( t , error ! , url ) ;
236236 }
237237
238238 {
239239 const error = await t . throwsAsync ( got ( url ) . buffer ( ) ) ;
240- invalidUrl ( t , error , url ) ;
240+ invalidUrl ( t , error ! , url ) ;
241241 }
242242} ) ;
243243
@@ -249,8 +249,8 @@ test('errors can have request property', withServer, async (t, server, got) => {
249249
250250 const error = await t . throwsAsync < HTTPError > ( got ( '' ) ) ;
251251
252- t . truthy ( error . response ) ;
253- t . truthy ( error . request . downloadProgress ) ;
252+ t . truthy ( error ? .response ) ;
253+ t . truthy ( error ? .request . downloadProgress ) ;
254254} ) ;
255255
256256test ( '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 => {
333333 } ,
334334 } ) ) ;
335335
336- t . true ( error . stack ! . includes ( 'at Object.request' ) ) ;
336+ t . true ( error ? .stack ! . includes ( 'at Object.request' ) ) ;
337337
338338 // The first `at get` points to where the error was wrapped,
339339 // 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' ) ) ;
341341} ) ;
342342
343343test . serial ( 'custom stack trace' , withServer , async ( t , _server , got ) => {
@@ -363,7 +363,7 @@ test.serial('custom stack trace', withServer, async (t, _server, got) => {
363363 stream . destroy ( new Error ( 'oh no' ) ) ;
364364
365365 const caught = await t . throwsAsync ( getStream ( stream ) ) ;
366- t . is ( is ( caught . stack ) , 'string' ) ;
366+ t . is ( is ( caught ? .stack ) , 'string' ) ;
367367 }
368368
369369 // Passing a custom error
@@ -376,7 +376,7 @@ test.serial('custom stack trace', withServer, async (t, _server, got) => {
376376 stream . destroy ( error ) ;
377377
378378 const caught = await t . throwsAsync ( getStream ( stream ) ) ;
379- t . is ( is ( caught . stack ) , 'string' ) ;
379+ t . is ( is ( caught ? .stack ) , 'string' ) ;
380380 }
381381
382382 // Custom global behavior
@@ -388,7 +388,7 @@ test.serial('custom stack trace', withServer, async (t, _server, got) => {
388388 stream . destroy ( error ) ;
389389
390390 const caught = await t . throwsAsync ( getStream ( stream ) ) ;
391- t . is ( is ( caught . stack ) , 'Array' ) ;
391+ t . is ( is ( caught ? .stack ) , 'Array' ) ;
392392
393393 disable ( ) ;
394394 }
@@ -402,7 +402,7 @@ test.serial('custom stack trace', withServer, async (t, _server, got) => {
402402 stream . destroy ( error ) ;
403403
404404 const caught = await t . throwsAsync ( getStream ( stream ) ) ;
405- t . is ( is ( caught . stack ) , 'Array' ) ;
405+ t . is ( is ( caught ? .stack ) , 'Array' ) ;
406406
407407 disable ( ) ;
408408 }
0 commit comments