@@ -314,14 +314,15 @@ test('Can parse text responses', async (t) => {
314314test ( 'Handle error empty responses' , async ( t ) => {
315315 const accountId = uuidv4 ( )
316316 const status = 404
317- const scope = nock ( origin ) . get ( `${ pathPrefix } /accounts/${ accountId } ` ) . reply ( status )
317+ const expectedResponse = 'test'
318+ const scope = nock ( origin ) . get ( `${ pathPrefix } /accounts/${ accountId } ` ) . reply ( status , expectedResponse )
318319
319320 const client = getClient ( )
320321 const error = await t . throwsAsync ( client . getAccount ( { account_id : accountId } ) )
321322
322323 t . is ( error . status , status )
323- t . is ( error . message , 'Not Found' )
324- t . is ( error . data , '' )
324+ t . is ( error . message , expectedResponse )
325+ t . is ( error . data , expectedResponse )
325326 t . true ( error instanceof TextHTTPError )
326327 t . true ( error . stack !== undefined )
327328 t . true ( scope . isDone ( ) )
@@ -337,7 +338,7 @@ test('Handle error text responses', async (t) => {
337338 const error = await t . throwsAsync ( client . getAccount ( { account_id : accountId } ) )
338339
339340 t . is ( error . status , status )
340- t . is ( error . message , 'Not Found' )
341+ t . is ( error . message , expectedResponse )
341342 t . is ( error . data , expectedResponse )
342343 t . true ( error instanceof TextHTTPError )
343344 t . true ( error . stack !== undefined )
@@ -356,7 +357,7 @@ test('Handle error text responses on JSON endpoints', async (t) => {
356357 const error = await t . throwsAsync ( client . getAccount ( { account_id : accountId } ) )
357358
358359 t . is ( error . status , status )
359- t . is ( error . message , 'Not Found' )
360+ t . is ( error . message , expectedResponse )
360361 t . is ( error . data , expectedResponse )
361362 t . true ( error instanceof TextHTTPError )
362363 t . true ( error . stack !== undefined )
@@ -373,7 +374,7 @@ test('Handle error JSON responses', async (t) => {
373374 const error = await t . throwsAsync ( client . getAccount ( { account_id : accountId } ) )
374375
375376 t . is ( error . status , status )
376- t . is ( error . message , 'Not Found' )
377+ t . notThrows ( ( ) => JSON . parse ( error . message ) )
377378 t . deepEqual ( error . json , errorJson )
378379 t . true ( error instanceof JSONHTTPError )
379380 t . true ( error . stack !== undefined )
@@ -550,7 +551,7 @@ test('Gives up retrying on API rate limiting after a timeout', async (t) => {
550551 const error = await t . throwsAsync ( client . getAccount ( { account_id : accountId } ) )
551552
552553 t . is ( error . status , 429 )
553- t . is ( error . message , 'Too Many Requests' )
554+ t . is ( error . message , JSON . stringify ( { retryAt } ) )
554555 t . true ( Number . isInteger ( error . json . retryAt ) )
555556
556557 t . false ( scope . isDone ( ) )
0 commit comments