1
- import { ISettings } from '../../../../ types/splitio ' ;
1
+ import { ISettings } from '../../../types' ;
2
2
import { ISplitChangesResponse } from '../../../dtos/types' ;
3
3
import { IFetchSplitChanges , IResponse } from '../../../services/types' ;
4
4
import { IStorageBase } from '../../../storages/types' ;
5
5
import { FLAG_SPEC_VERSION } from '../../../utils/constants' ;
6
6
import { base } from '../../../utils/settingsValidation' ;
7
7
import { ISplitChangesFetcher } from './types' ;
8
+ import { LOG_PREFIX_SYNC_SPLITS } from '../../../logger/constants' ;
8
9
9
10
const PROXY_CHECK_INTERVAL_MILLIS_CS = 60 * 60 * 1000 ; // 1 hour in Client Side
10
11
const PROXY_CHECK_INTERVAL_MILLIS_SS = 24 * PROXY_CHECK_INTERVAL_MILLIS_CS ; // 24 hours in Server Side
@@ -20,6 +21,7 @@ function sdkEndpointOverriden(settings: ISettings) {
20
21
// @TODO breaking: drop support for Split Proxy below v5.10.0 and simplify the implementation
21
22
export function splitChangesFetcherFactory ( fetchSplitChanges : IFetchSplitChanges , settings : ISettings , storage : Pick < IStorageBase , 'splits' | 'rbSegments' > ) : ISplitChangesFetcher {
22
23
24
+ const log = settings . log ;
23
25
const PROXY_CHECK_INTERVAL_MILLIS = settings . core . key !== undefined ? PROXY_CHECK_INTERVAL_MILLIS_CS : PROXY_CHECK_INTERVAL_MILLIS_SS ;
24
26
let lastProxyCheckTimestamp : number | undefined ;
25
27
@@ -41,6 +43,7 @@ export function splitChangesFetcherFactory(fetchSplitChanges: IFetchSplitChanges
41
43
// Handle proxy error with spec 1.3
42
44
. catch ( ( err ) => {
43
45
if ( err . statusCode === 400 && sdkEndpointOverriden ( settings ) && settings . sync . flagSpecVersion === FLAG_SPEC_VERSION ) {
46
+ log . error ( LOG_PREFIX_SYNC_SPLITS + 'Proxy error detected. If you are using Split Proxy, please upgrade to latest version' ) ;
44
47
lastProxyCheckTimestamp = Date . now ( ) ;
45
48
settings . sync . flagSpecVersion = '1.2' ; // fallback to 1.2 spec
46
49
return fetchSplitChanges ( since , noCache , till ) ; // retry request without rbSince
@@ -66,6 +69,7 @@ export function splitChangesFetcherFactory(fetchSplitChanges: IFetchSplitChanges
66
69
67
70
// Proxy recovery
68
71
if ( lastProxyCheckTimestamp ) {
72
+ log . info ( LOG_PREFIX_SYNC_SPLITS + 'Proxy error recovered' ) ;
69
73
lastProxyCheckTimestamp = undefined ;
70
74
return Promise . all ( [ storage . splits . clear ( ) , storage . rbSegments . clear ( ) ] )
71
75
. then ( ( ) => splitChangesFetcher ( storage . splits . getChangeNumber ( ) as number , undefined , undefined , storage . rbSegments . getChangeNumber ( ) as number ) ) ;
0 commit comments