@@ -21,71 +21,85 @@ import { errors as esErrors } from '@elastic/elasticsearch';
2121import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks' ;
2222import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors' ;
2323
24- describe ( 'catchRetryableEsClientErrors returns left retryable_es_client_error for' , ( ) => {
25- it ( 'NoLivingConnectionsError' , async ( ) => {
26- const error = new esErrors . NoLivingConnectionsError (
27- 'reason' ,
28- elasticsearchClientMock . createApiResponse ( )
24+ describe ( 'catchRetryableEsClientErrors' , ( ) => {
25+ it ( 'rejects non-retryable response errors' , ( ) => {
26+ const error = new esErrors . ResponseError (
27+ elasticsearchClientMock . createApiResponse ( {
28+ body : { error : { type : 'cluster_block_exception' } } ,
29+ statusCode : 400 ,
30+ } )
2931 ) ;
30- expect (
31- ( ( await Promise . reject ( error ) . catch ( catchRetryableEsClientErrors ) ) as any ) . left
32- ) . toMatchObject ( {
33- message : 'reason' ,
34- type : 'retryable_es_client_error' ,
35- } ) ;
32+ return expect ( Promise . reject ( error ) . catch ( catchRetryableEsClientErrors ) ) . rejects . toBe ( error ) ;
3633 } ) ;
34+ describe ( 'returns left retryable_es_client_error for' , ( ) => {
35+ it ( 'NoLivingConnectionsError' , async ( ) => {
36+ const error = new esErrors . NoLivingConnectionsError (
37+ 'reason' ,
38+ elasticsearchClientMock . createApiResponse ( )
39+ ) ;
40+ expect (
41+ ( ( await Promise . reject ( error ) . catch ( catchRetryableEsClientErrors ) ) as any ) . left
42+ ) . toMatchObject ( {
43+ message : 'reason' ,
44+ type : 'retryable_es_client_error' ,
45+ } ) ;
46+ } ) ;
3747
38- it ( 'ConnectionError' , async ( ) => {
39- const error = new esErrors . ConnectionError (
40- 'reason' ,
41- elasticsearchClientMock . createApiResponse ( )
42- ) ;
43- expect (
44- ( ( await Promise . reject ( error ) . catch ( catchRetryableEsClientErrors ) ) as any ) . left
45- ) . toMatchObject ( {
46- message : 'reason' ,
47- type : 'retryable_es_client_error' ,
48+ it ( 'ConnectionError' , async ( ) => {
49+ const error = new esErrors . ConnectionError (
50+ 'reason' ,
51+ elasticsearchClientMock . createApiResponse ( )
52+ ) ;
53+ expect (
54+ ( ( await Promise . reject ( error ) . catch ( catchRetryableEsClientErrors ) ) as any ) . left
55+ ) . toMatchObject ( {
56+ message : 'reason' ,
57+ type : 'retryable_es_client_error' ,
58+ } ) ;
4859 } ) ;
49- } ) ;
50- it ( 'TimeoutError' , async ( ) => {
51- const error = new esErrors . TimeoutError ( 'reason' , elasticsearchClientMock . createApiResponse ( ) ) ;
52- expect (
53- ( ( await Promise . reject ( error ) . catch ( catchRetryableEsClientErrors ) ) as any ) . left
54- ) . toMatchObject ( {
55- message : 'reason' ,
56- type : 'retryable_es_client_error' ,
60+ it ( 'TimeoutError' , async ( ) => {
61+ const error = new esErrors . TimeoutError (
62+ 'reason' ,
63+ elasticsearchClientMock . createApiResponse ( )
64+ ) ;
65+ expect (
66+ ( ( await Promise . reject ( error ) . catch ( catchRetryableEsClientErrors ) ) as any ) . left
67+ ) . toMatchObject ( {
68+ message : 'reason' ,
69+ type : 'retryable_es_client_error' ,
70+ } ) ;
5771 } ) ;
58- } ) ;
59- it ( 'ResponseError of type snapshot_in_progress_exception' , async ( ) => {
60- const error = new esErrors . ResponseError (
61- elasticsearchClientMock . createApiResponse ( {
62- body : { error : { type : 'snapshot_in_progress_exception' } } ,
63- } )
64- ) ;
65- expect (
66- ( ( await Promise . reject ( error ) . catch ( catchRetryableEsClientErrors ) ) as any ) . left
67- ) . toMatchObject ( {
68- message : 'snapshot_in_progress_exception' ,
69- type : 'retryable_es_client_error' ,
72+ it ( 'ResponseError of type snapshot_in_progress_exception' , async ( ) => {
73+ const error = new esErrors . ResponseError (
74+ elasticsearchClientMock . createApiResponse ( {
75+ body : { error : { type : 'snapshot_in_progress_exception' } } ,
76+ } )
77+ ) ;
78+ expect (
79+ ( ( await Promise . reject ( error ) . catch ( catchRetryableEsClientErrors ) ) as any ) . left
80+ ) . toMatchObject ( {
81+ message : 'snapshot_in_progress_exception' ,
82+ type : 'retryable_es_client_error' ,
83+ } ) ;
84+ } ) ;
85+ it ( 'ResponseError with retryable status code' , async ( ) => {
86+ const statusCodes = [ 503 , 401 , 403 , 408 , 410 ] ;
87+ return Promise . all (
88+ statusCodes . map ( async ( status ) => {
89+ const error = new esErrors . ResponseError (
90+ elasticsearchClientMock . createApiResponse ( {
91+ statusCode : status ,
92+ body : { error : { type : 'reason' } } ,
93+ } )
94+ ) ;
95+ expect (
96+ ( ( await Promise . reject ( error ) . catch ( catchRetryableEsClientErrors ) ) as any ) . left
97+ ) . toMatchObject ( {
98+ message : 'reason' ,
99+ type : 'retryable_es_client_error' ,
100+ } ) ;
101+ } )
102+ ) ;
70103 } ) ;
71- } ) ;
72- it ( 'ResponseError with retryable status code' , async ( ) => {
73- const statusCodes = [ 503 , 401 , 403 , 408 , 410 ] ;
74- return Promise . all (
75- statusCodes . map ( async ( status ) => {
76- const error = new esErrors . ResponseError (
77- elasticsearchClientMock . createApiResponse ( {
78- statusCode : status ,
79- body : { error : { type : 'reason' } } ,
80- } )
81- ) ;
82- expect (
83- ( ( await Promise . reject ( error ) . catch ( catchRetryableEsClientErrors ) ) as any ) . left
84- ) . toMatchObject ( {
85- message : 'reason' ,
86- type : 'retryable_es_client_error' ,
87- } ) ;
88- } )
89- ) ;
90104 } ) ;
91105} ) ;
0 commit comments