From 7c9ee78402a85cf16db7511c5baae833d0a01485 Mon Sep 17 00:00:00 2001 From: Md Junaed Hossain <169046794+junaed-optimizely@users.noreply.github.com> Date: Sat, 14 Dec 2024 00:11:18 +0600 Subject: [PATCH] [FSSDK-10935] log adjustment --- lib/error_messages.ts | 17 +++++++++--- lib/exception_messages.ts | 5 ++++ lib/index.browser.tests.js | 5 ++-- lib/log_messages.ts | 6 +++++ .../odp_event_api_manager.spec.ts | 4 +-- .../event_manager/odp_event_manager.spec.ts | 5 ++-- lib/odp/event_manager/odp_event_manager.ts | 27 ++++++++++++------- lib/odp/odp_manager.spec.ts | 7 ++--- lib/odp/odp_manager.ts | 3 ++- .../odp_segment_api_manager.spec.ts | 3 ++- lib/optimizely/index.ts | 5 ++-- ...onfig_manager_factory.react_native.spec.ts | 2 +- .../polling_datafile_manager.ts | 18 ++++++++----- lib/project_config/project_config_manager.ts | 14 ++++++---- .../browser_request_handler.ts | 3 ++- lib/vuid/vuid_manager_factory.node.spec.ts | 3 ++- lib/vuid/vuid_manager_factory.node.ts | 3 ++- 17 files changed, 86 insertions(+), 44 deletions(-) diff --git a/lib/error_messages.ts b/lib/error_messages.ts index 1a48f3832..29fcb8b41 100644 --- a/lib/error_messages.ts +++ b/lib/error_messages.ts @@ -49,6 +49,8 @@ export const NO_EVENT_PROCESSOR = 'No event processor is provided'; export const NO_VARIATION_FOR_EXPERIMENT_KEY = '%s: No variation key %s defined in datafile for experiment %s.'; export const ODP_CONFIG_NOT_AVAILABLE = '%s: ODP is not integrated to the project.'; export const ODP_EVENT_FAILED = 'ODP event send failed.'; +export const ODP_EVENT_MANAGER_IS_NOT_RUNNING = 'ODP event manager is not running.'; +export const ODP_EVENTS_SHOULD_HAVE_ATLEAST_ONE_KEY_VALUE = 'ODP events should have at least one key-value pair in identifiers.'; export const ODP_FETCH_QUALIFIED_SEGMENTS_SEGMENTS_MANAGER_MISSING = '%s: ODP unable to fetch qualified segments (Segments Manager not initialized).'; export const ODP_IDENTIFY_FAILED_EVENT_MANAGER_MISSING = @@ -93,7 +95,14 @@ export const INVALID_INPUT_FORMAT = '%s: Provided %s is in an invalid format.'; export const INVALID_DATAFILE_VERSION = '%s: This version of the JavaScript SDK does not support the given datafile version: %s'; export const INVALID_VARIATION_KEY = '%s: Provided variation key is in an invalid format.'; -export const UNABLE_TO_GET_VUID = 'Unable to get VUID - ODP Manager is not instantiated yet.' -export const ERROR_FETCHING_DATAFILE = 'Error fetching datafile: %s' -export const DATAFILE_FETCH_REQUEST_FAILED = 'Datafile fetch request failed with status: %s' -export const ONRUNNING_ERROR = 'onRunning error' +export const UNABLE_TO_GET_VUID = 'Unable to get VUID - ODP Manager is not instantiated yet.'; +export const ERROR_FETCHING_DATAFILE = 'Error fetching datafile: %s'; +export const DATAFILE_FETCH_REQUEST_FAILED = 'Datafile fetch request failed with status: %s'; +export const ONRUNNING_ERROR = 'onRunning error'; +export const EVENT_DATA_FOUND_TO_BE_INVALID = 'Event data found to be invalid.'; +export const EVENT_ACTION_INVALID = 'Event action invalid.'; +export const FAILED_TO_SEND_ODP_EVENTS = 'failed to send odp events'; +export const UNABLE_TO_OVERWRITE_GLOBAL_WINDOW = 'Unable to overwrite global.window.'; +export const UNABLE_TO_GET_VUID_VUID_MANAGER_NOT_AVAILABLE = 'Unable to get VUID - VuidManager is not available' + + diff --git a/lib/exception_messages.ts b/lib/exception_messages.ts index 405670406..83965589f 100644 --- a/lib/exception_messages.ts +++ b/lib/exception_messages.ts @@ -23,16 +23,20 @@ export const SEND_BEACON_FAILED = 'sendBeacon failed'; export const CANNOT_START_WITHOUT_ODP_CONFIG = 'cannot start without ODP config'; export const START_CALLED_WHEN_ODP_IS_NOT_INTEGRATED = 'start() called when ODP is not integrated'; export const ODP_ACTION_IS_NOT_VALID = 'ODP action is not valid (cannot be empty).'; +export const ODP_MANAGER_STOPPED_BEFORE_RUNNING = 'odp manager stopped before running'; +export const ODP_EVENT_MANAGER_STOPPED = "ODP event manager stopped before it could start"; export const ONREADY_TIMEOUT_EXPIRED = 'onReady timeout expired after %s ms'; export const INSTANCE_CLOSED = 'Instance closed'; export const DATAFILE_MANAGER_STOPPED = 'Datafile manager stopped before it could be started'; export const DATAFILE_MANAGER_FAILED_TO_START = 'Datafile manager failed to start'; export const FAILED_TO_FETCH_DATAFILE = 'Failed to fetch datafile'; +export const FAILED_TO_START = 'Failed to start'; export const FAILED_TO_STOP = 'Failed to stop'; export const YOU_MUST_PROVIDE_DATAFILE_IN_SSR = 'You must provide datafile in SSR'; export const YOU_MUST_PROVIDE_AT_LEAST_ONE_OF_SDKKEY_OR_DATAFILE = 'You must provide at least one of sdkKey or datafile'; export const RETRY_CANCELLED = 'Retry cancelled'; export const REQUEST_ERROR = 'Request error'; +export const REQUEST_FAILED = 'Request failed'; export const UNSUPPORTED_PROTOCOL = 'Unsupported protocol: %s'; export const REQUEST_TIMEOUT = 'Request timed out'; export const NO_STATUS_CODE_IN_RESPONSE = 'No status code in response'; @@ -40,3 +44,4 @@ export const MODULE_NOT_FOUND_REACT_NATIVE_ASYNC_STORAGE = 'Module not found: @r export const MODULE_NOT_FOUND_REACT_NATIVE_NETINFO = 'Module not found: @react-native-community/netinfo'; export const INVALID_CONFIG_OR_SOMETHING = 'Invalid config or something'; export const PROMISE_SHOULD_NOT_HAVE_RESOLVED = 'Promise should not have resolved'; +export const VUID_IS_NOT_SUPPORTED_IN_NODEJS= 'VUID is not supported in Node.js environment'; diff --git a/lib/index.browser.tests.js b/lib/index.browser.tests.js index 6facf2278..57990d5bd 100644 --- a/lib/index.browser.tests.js +++ b/lib/index.browser.tests.js @@ -24,8 +24,7 @@ import optimizelyFactory from './index.browser'; import configValidator from './utils/config_validator'; import { getMockProjectConfigManager } from './tests/mock/mock_project_config_manager'; import { createProjectConfig } from './project_config/project_config'; -import { ODP_EVENT_FAILED_ODP_MANAGER_MISSING } from './error_messages'; -import { ODP_DISABLED, ODP_SEND_EVENT_IDENTIFIER_CONVERSION_FAILED } from './log_messages'; +import { UNABLE_TO_OVERWRITE_GLOBAL_WINDOW } from './error_messages'; import { INVALID_CONFIG_OR_SOMETHING } from './exception_messages'; @@ -57,7 +56,7 @@ if (!global.window) { localStorage: new MockLocalStorage(), }; } catch (e) { - console.error('Unable to overwrite global.window.'); + console.error(UNABLE_TO_OVERWRITE_GLOBAL_WINDOW); } } diff --git a/lib/log_messages.ts b/lib/log_messages.ts index faa180656..e5cdbd2fe 100644 --- a/lib/log_messages.ts +++ b/lib/log_messages.ts @@ -123,3 +123,9 @@ export const UPDATED_OPTIMIZELY_CONFIG = '%s: Updated Optimizely config to revis export const OUT_OF_BOUNDS = '%s: Audience condition %s evaluated to UNKNOWN because the number value for user attribute "%s" is not in the range [-2^53, +2^53].'; export const UNABLE_TO_ATTACH_UNLOAD = '%s: unable to bind optimizely.close() to page unload event: "%s"'; +export const UNABLE_TO_PARSE_AND_SKIPPED_HEADER = 'Unable to parse & skipped header item'; +export const ADDING_AUTHORIZATION_HEADER_WITH_BEARER_TOKEN = 'Adding Authorization header with Bearer Token'; +export const MAKING_DATAFILE_REQ_TO_URL_WITH_HEADERS = 'Making datafile request to url %s with headers: %s'; +export const RESPONSE_STATUS_CODE = 'Response status code: %s'; +export const SAVED_LAST_MODIFIED_HEADER_VALUE_FROM_RESPONSE = 'Saved last modified header value from response: %s'; + diff --git a/lib/odp/event_manager/odp_event_api_manager.spec.ts b/lib/odp/event_manager/odp_event_api_manager.spec.ts index 8f6a07fd2..55ec009e1 100644 --- a/lib/odp/event_manager/odp_event_api_manager.spec.ts +++ b/lib/odp/event_manager/odp_event_api_manager.spec.ts @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - import { describe, it, expect, vi } from 'vitest'; import { DefaultOdpEventApiManager, eventApiRequestGenerator, pixelApiRequestGenerator } from './odp_event_api_manager'; @@ -42,6 +41,7 @@ const PIXEL_URL = 'https://odp.pixel.com'; const odpConfig = new OdpConfig(API_KEY, API_HOST, PIXEL_URL, []); import { getMockRequestHandler } from '../../tests/mock/mock_request_handler'; +import { REQUEST_FAILED } from '../../exception_messages'; describe('DefaultOdpEventApiManager', () => { it('should generate the event request using the correct odp config and event', async () => { @@ -101,7 +101,7 @@ describe('DefaultOdpEventApiManager', () => { it('should return a promise that fails if the requestHandler response promise fails', async () => { const mockRequestHandler = getMockRequestHandler(); mockRequestHandler.makeRequest.mockReturnValue({ - responsePromise: Promise.reject(new Error('Request failed')), + responsePromise: Promise.reject(new Error(REQUEST_FAILED)), }); const requestGenerator = vi.fn().mockReturnValue({ method: 'PATCH', diff --git a/lib/odp/event_manager/odp_event_manager.spec.ts b/lib/odp/event_manager/odp_event_manager.spec.ts index dfe8d496a..f0acb144a 100644 --- a/lib/odp/event_manager/odp_event_manager.spec.ts +++ b/lib/odp/event_manager/odp_event_manager.spec.ts @@ -23,6 +23,7 @@ import { OdpEvent } from './odp_event'; import { OdpConfig } from '../odp_config'; import { EventDispatchResponse } from './odp_event_api_manager'; import { advanceTimersByTime } from '../../../tests/testUtils'; +import { FAILED_TO_DISPATCH_EVENTS } from '../../exception_messages'; const API_KEY = 'test-api-key'; const API_HOST = 'https://odp.example.com'; @@ -604,7 +605,7 @@ describe('DefaultOdpEventManager', () => { const repeater = getMockRepeater(); const apiManager = getMockApiManager(); - apiManager.sendEvents.mockReturnValue(Promise.reject(new Error('Failed to dispatch events'))); + apiManager.sendEvents.mockReturnValue(Promise.reject(new Error(FAILED_TO_DISPATCH_EVENTS))); const backoffController = { backoff: vi.fn().mockReturnValue(666), @@ -706,7 +707,7 @@ describe('DefaultOdpEventManager', () => { const repeater = getMockRepeater(); const apiManager = getMockApiManager(); - apiManager.sendEvents.mockReturnValue(Promise.reject(new Error('Failed to dispatch events'))); + apiManager.sendEvents.mockReturnValue(Promise.reject(new Error(FAILED_TO_DISPATCH_EVENTS))); const backoffController = { backoff: vi.fn().mockReturnValue(666), diff --git a/lib/odp/event_manager/odp_event_manager.ts b/lib/odp/event_manager/odp_event_manager.ts index 286c181ef..6ebe5aaa0 100644 --- a/lib/odp/event_manager/odp_event_manager.ts +++ b/lib/odp/event_manager/odp_event_manager.ts @@ -23,7 +23,16 @@ import { Producer } from '../../utils/type'; import { runWithRetry } from '../../utils/executor/backoff_retry_runner'; import { isSuccessStatusCode } from '../../utils/http_request_handler/http_util'; import { ODP_DEFAULT_EVENT_TYPE, ODP_USER_KEY } from '../constant'; -import { ODP_NOT_INTEGRATED } from '../../error_messages'; +import { + EVENT_ACTION_INVALID, + EVENT_DATA_FOUND_TO_BE_INVALID, + FAILED_TO_SEND_ODP_EVENTS, + ODP_EVENT_MANAGER_IS_NOT_RUNNING, + ODP_EVENTS_SHOULD_HAVE_ATLEAST_ONE_KEY_VALUE, + ODP_NOT_INTEGRATED, +} from '../../error_messages'; +import { sprintf } from '../../utils/fns'; +import { FAILED_TO_DISPATCH_EVENTS_WITH_ARG, ODP_EVENT_MANAGER_STOPPED } from '../../exception_messages'; export interface OdpEventManager extends Service { updateConfig(odpIntegrationConfig: OdpIntegrationConfig): void; @@ -66,8 +75,7 @@ export class DefaultOdpEventManager extends BaseService implements OdpEventManag private async executeDispatch(odpConfig: OdpConfig, batch: OdpEvent[]): Promise { const res = await this.apiManager.sendEvents(odpConfig, batch); if (res.statusCode && !isSuccessStatusCode(res.statusCode)) { - // TODO: replace message with imported constants - return Promise.reject(new Error(`Failed to dispatch events: ${res.statusCode}`)); + return Promise.reject(new Error(sprintf(FAILED_TO_DISPATCH_EVENTS_WITH_ARG, res.statusCode))); } return await Promise.resolve(res); } @@ -89,8 +97,7 @@ export class DefaultOdpEventManager extends BaseService implements OdpEventManag return runWithRetry( () => this.executeDispatch(odpConfig, batch), this.retryConfig.backoffProvider(), this.retryConfig.maxRetries ).result.catch((err) => { - // TODO: replace with imported constants - this.logger?.error('failed to send odp events', err); + this.logger?.error(FAILED_TO_SEND_ODP_EVENTS, err); }); } @@ -139,7 +146,7 @@ export class DefaultOdpEventManager extends BaseService implements OdpEventManag } if (this.isNew()) { - this.startPromise.reject(new Error('odp event manager stopped before it could start')); + this.startPromise.reject(new Error(ODP_EVENT_MANAGER_STOPPED)); } this.flush(); @@ -149,7 +156,7 @@ export class DefaultOdpEventManager extends BaseService implements OdpEventManag sendEvent(event: OdpEvent): void { if (!this.isRunning()) { - this.logger?.error('ODP event manager is not running.'); + this.logger?.error(ODP_EVENT_MANAGER_IS_NOT_RUNNING); return; } @@ -159,17 +166,17 @@ export class DefaultOdpEventManager extends BaseService implements OdpEventManag } if (event.identifiers.size === 0) { - this.logger?.error('ODP events should have at least one key-value pair in identifiers.'); + this.logger?.error(ODP_EVENTS_SHOULD_HAVE_ATLEAST_ONE_KEY_VALUE); return; } if (!this.isDataValid(event.data)) { - this.logger?.error('Event data found to be invalid.'); + this.logger?.error(EVENT_DATA_FOUND_TO_BE_INVALID); return; } if (!event.action ) { - this.logger?.error('Event action invalid.'); + this.logger?.error(EVENT_ACTION_INVALID); return; } diff --git a/lib/odp/odp_manager.spec.ts b/lib/odp/odp_manager.spec.ts index 2464bc28b..8895abcd1 100644 --- a/lib/odp/odp_manager.spec.ts +++ b/lib/odp/odp_manager.spec.ts @@ -25,6 +25,7 @@ import { ODP_USER_KEY } from './constant'; import { OptimizelySegmentOption } from './segment_manager/optimizely_segment_option'; import { OdpEventManager } from './event_manager/odp_event_manager'; import { CLIENT_VERSION, JAVASCRIPT_CLIENT_ENGINE } from '../utils/enums'; +import { FAILED_TO_START, FAILED_TO_STOP } from '../exception_messages'; const keyA = 'key-a'; const hostA = 'host-a'; @@ -166,7 +167,7 @@ describe('DefaultOdpManager', () => { await exhaustMicrotasks(); expect(odpManager.getState()).toEqual(ServiceState.Starting); - eventManagerPromise.reject(new Error('Failed to start')); + eventManagerPromise.reject(new Error(FAILED_TO_START)); await expect(odpManager.onRunning()).rejects.toThrow(); await expect(odpManager.onTerminated()).rejects.toThrow(); @@ -186,7 +187,7 @@ describe('DefaultOdpManager', () => { odpManager.start(); expect(odpManager.getState()).toEqual(ServiceState.Starting); - eventManagerPromise.reject(new Error('Failed to start')); + eventManagerPromise.reject(new Error(FAILED_TO_START)); await expect(odpManager.onRunning()).rejects.toThrow(); await expect(odpManager.onTerminated()).rejects.toThrow(); @@ -692,7 +693,7 @@ describe('DefaultOdpManager', () => { await exhaustMicrotasks(); expect(odpManager.getState()).toEqual(ServiceState.Stopping); - eventManagerTerminatedPromise.reject(new Error('Failed to stop')); + eventManagerTerminatedPromise.reject(new Error(FAILED_TO_STOP)); await expect(odpManager.onTerminated()).rejects.toThrow(); }); }); diff --git a/lib/odp/odp_manager.ts b/lib/odp/odp_manager.ts index 560e445a4..05c476ff3 100644 --- a/lib/odp/odp_manager.ts +++ b/lib/odp/odp_manager.ts @@ -29,6 +29,7 @@ import { CLIENT_VERSION, JAVASCRIPT_CLIENT_ENGINE } from '../utils/enums'; import { ODP_DEFAULT_EVENT_TYPE, ODP_EVENT_ACTION, ODP_USER_KEY } from './constant'; import { isVuid } from '../vuid/vuid'; import { Maybe } from '../utils/type'; +import { ODP_MANAGER_STOPPED_BEFORE_RUNNING } from '../exception_messages'; export interface OdpManager extends Service { updateConfig(odpIntegrationConfig: OdpIntegrationConfig): boolean; @@ -131,7 +132,7 @@ export class DefaultOdpManager extends BaseService implements OdpManager { } if (!this.isRunning()) { - this.startPromise.reject(new Error('odp manager stopped before running')); + this.startPromise.reject(new Error(ODP_MANAGER_STOPPED_BEFORE_RUNNING)); } this.state = ServiceState.Stopping; diff --git a/lib/odp/segment_manager/odp_segment_api_manager.spec.ts b/lib/odp/segment_manager/odp_segment_api_manager.spec.ts index 52237add9..cc5e8782c 100644 --- a/lib/odp/segment_manager/odp_segment_api_manager.spec.ts +++ b/lib/odp/segment_manager/odp_segment_api_manager.spec.ts @@ -20,6 +20,7 @@ import { ODP_USER_KEY } from '../constant'; import { getMockRequestHandler } from '../../tests/mock/mock_request_handler'; import { getMockLogger } from '../../tests/mock/mock_logger'; import { DefaultOdpSegmentApiManager } from './odp_segment_api_manager'; +import { REQUEST_TIMEOUT } from '../../exception_messages'; const API_KEY = 'not-real-api-key'; const GRAPHQL_ENDPOINT = 'https://some.example.com/graphql/endpoint'; @@ -46,7 +47,7 @@ describe('DefaultOdpSegmentApiManager', () => { const requestHandler = getMockRequestHandler(); requestHandler.makeRequest.mockReturnValue({ abort: () => {}, - responsePromise: Promise.reject(new Error('Request timed out')), + responsePromise: Promise.reject(new Error(REQUEST_TIMEOUT)), }); const logger = getMockLogger(); const manager = new DefaultOdpSegmentApiManager(requestHandler, logger); diff --git a/lib/optimizely/index.ts b/lib/optimizely/index.ts index e16a5e135..34fa116f6 100644 --- a/lib/optimizely/index.ts +++ b/lib/optimizely/index.ts @@ -73,7 +73,7 @@ import { NO_EVENT_PROCESSOR, ODP_EVENT_FAILED, ODP_EVENT_FAILED_ODP_MANAGER_MISSING, - UNABLE_TO_GET_VUID, + UNABLE_TO_GET_VUID_VUID_MANAGER_NOT_AVAILABLE, } from '../error_messages'; import { EVENT_KEY_NOT_FOUND, @@ -86,7 +86,6 @@ import { INVALID_OBJECT, NOT_ACTIVATING_USER, NOT_TRACKING_USER, - ODP_SEND_EVENT_IDENTIFIER_CONVERSION_FAILED, SHOULD_NOT_DISPATCH_ACTIVATE, TRACK_EVENT, UNRECOGNIZED_DECIDE_OPTION, @@ -1736,7 +1735,7 @@ export default class Optimizely implements Client { */ public getVuid(): string | undefined { if (!this.vuidManager) { - this.logger?.error('Unable to get VUID - VuidManager is not available'); + this.logger?.error(UNABLE_TO_GET_VUID_VUID_MANAGER_NOT_AVAILABLE); return undefined; } diff --git a/lib/project_config/config_manager_factory.react_native.spec.ts b/lib/project_config/config_manager_factory.react_native.spec.ts index 5ea2d56e3..5a88bb015 100644 --- a/lib/project_config/config_manager_factory.react_native.spec.ts +++ b/lib/project_config/config_manager_factory.react_native.spec.ts @@ -30,7 +30,7 @@ async function mockRequireAsyncStorage() { M._load = (uri: string, parent: string) => { if (uri === '@react-native-async-storage/async-storage') { if (isAsyncStorageAvailable) return { default: {} }; - throw new Error('Module not found: @react-native-async-storage/async-storage'); + throw new Error(MODULE_NOT_FOUND_REACT_NATIVE_ASYNC_STORAGE); } return M._load_original(uri, parent); }; diff --git a/lib/project_config/polling_datafile_manager.ts b/lib/project_config/polling_datafile_manager.ts index 6d05b89ec..bde704029 100644 --- a/lib/project_config/polling_datafile_manager.ts +++ b/lib/project_config/polling_datafile_manager.ts @@ -25,6 +25,12 @@ import { Consumer, Fn } from '../utils/type'; import { isSuccessStatusCode } from '../utils/http_request_handler/http_util'; import { DATAFILE_MANAGER_STOPPED, FAILED_TO_FETCH_DATAFILE } from '../exception_messages'; import { DATAFILE_FETCH_REQUEST_FAILED, ERROR_FETCHING_DATAFILE } from '../error_messages'; +import { + ADDING_AUTHORIZATION_HEADER_WITH_BEARER_TOKEN, + MAKING_DATAFILE_REQ_TO_URL_WITH_HEADERS, + RESPONSE_STATUS_CODE, + SAVED_LAST_MODIFIED_HEADER_VALUE_FROM_RESPONSE, +} from '../log_messages'; export class PollingDatafileManager extends BaseService implements DatafileManager { private requestHandler: RequestHandler; @@ -98,8 +104,8 @@ export class PollingDatafileManager extends BaseService implements DatafileManag if (this.isNew() || this.isStarting()) { this.startPromise.reject(new Error(DATAFILE_MANAGER_STOPPED)); } - // Todo: Replace this with constant - this.logger?.debug('Datafile manager stopped'); + + this.logger?.debug(DATAFILE_MANAGER_STOPPED); this.state = ServiceState.Terminated; this.repeater.stop(); this.currentRequest?.abort(); @@ -169,11 +175,11 @@ export class PollingDatafileManager extends BaseService implements DatafileManag } if (this.datafileAccessToken) { - this.logger?.debug('Adding Authorization header with Bearer Token'); + this.logger?.debug(ADDING_AUTHORIZATION_HEADER_WITH_BEARER_TOKEN); headers['Authorization'] = `Bearer ${this.datafileAccessToken}`; } - this.logger?.debug('Making datafile request to url %s with headers: %s', this.datafileUrl, () => JSON.stringify(headers)); + this.logger?.debug(MAKING_DATAFILE_REQ_TO_URL_WITH_HEADERS, this.datafileUrl, () => JSON.stringify(headers)); return this.requestHandler.makeRequest(this.datafileUrl, headers, 'GET'); } @@ -200,7 +206,7 @@ export class PollingDatafileManager extends BaseService implements DatafileManag } private getDatafileFromResponse(response: Response): string | undefined{ - this.logger?.debug('Response status code: %s', response.statusCode); + this.logger?.debug(RESPONSE_STATUS_CODE, response.statusCode); if (response.statusCode === 304) { return undefined; } @@ -211,7 +217,7 @@ export class PollingDatafileManager extends BaseService implements DatafileManag const lastModifiedHeader = headers['last-modified'] || headers['Last-Modified']; if (lastModifiedHeader !== undefined) { this.lastResponseLastModified = lastModifiedHeader; - this.logger?.debug('Saved last modified header value from response: %s', this.lastResponseLastModified); + this.logger?.debug(SAVED_LAST_MODIFIED_HEADER_VALUE_FROM_RESPONSE, this.lastResponseLastModified); } } diff --git a/lib/project_config/project_config_manager.ts b/lib/project_config/project_config_manager.ts index 7e1f59a14..81ee87b78 100644 --- a/lib/project_config/project_config_manager.ts +++ b/lib/project_config/project_config_manager.ts @@ -22,7 +22,12 @@ import { scheduleMicrotask } from '../utils/microtask'; import { Service, ServiceState, BaseService } from '../service'; import { Consumer, Fn, Transformer } from '../utils/type'; import { EventEmitter } from '../utils/event_emitter/event_emitter'; -import { DATAFILE_MANAGER_FAILED_TO_START, DATAFILE_MANAGER_STOPPED } from '../exception_messages'; +import { + DATAFILE_MANAGER_FAILED_TO_START, + DATAFILE_MANAGER_STOPPED, + YOU_MUST_PROVIDE_AT_LEAST_ONE_OF_SDKKEY_OR_DATAFILE, + YOU_MUST_PROVIDE_DATAFILE_IN_SSR, +} from '../exception_messages'; interface ProjectConfigManagerConfig { // TODO: Don't use object type @@ -79,9 +84,9 @@ export class ProjectConfigManagerImpl extends BaseService implements ProjectConf if (!this.datafile && !this.datafileManager) { const errorMessage = this.isSsr - ? 'You must provide datafile in SSR' - : 'You must provide at least one of sdkKey or datafile'; - // TODO: replace message with imported constants + ? YOU_MUST_PROVIDE_DATAFILE_IN_SSR + : YOU_MUST_PROVIDE_AT_LEAST_ONE_OF_SDKKEY_OR_DATAFILE; + this.handleInitError(new Error(errorMessage)); return; } @@ -114,7 +119,6 @@ export class ProjectConfigManagerImpl extends BaseService implements ProjectConf } private handleDatafileManagerError(err: Error): void { - // TODO: replace message with imported constants this.logger?.error(DATAFILE_MANAGER_FAILED_TO_START, err); // If datafile manager onRunning() promise is rejected, and the project config manager diff --git a/lib/utils/http_request_handler/browser_request_handler.ts b/lib/utils/http_request_handler/browser_request_handler.ts index 06b9606d6..26e22425d 100644 --- a/lib/utils/http_request_handler/browser_request_handler.ts +++ b/lib/utils/http_request_handler/browser_request_handler.ts @@ -18,6 +18,7 @@ import { AbortableRequest, Headers, RequestHandler, Response } from './http'; import { LogHandler, LogLevel } from '../../modules/logging'; import { REQUEST_TIMEOUT_MS } from '../enums'; import { REQUEST_ERROR, REQUEST_TIMEOUT } from '../../exception_messages'; +import { UNABLE_TO_PARSE_AND_SKIPPED_HEADER } from '../../log_messages'; /** * Handles sending requests and receiving responses over HTTP via XMLHttpRequest @@ -123,7 +124,7 @@ export class BrowserRequestHandler implements RequestHandler { } } } catch { - this.logger?.log(LogLevel.WARNING, `Unable to parse & skipped header item '${headerLine}'`); + this.logger?.log(LogLevel.WARNING, UNABLE_TO_PARSE_AND_SKIPPED_HEADER, headerLine); } }); return headers; diff --git a/lib/vuid/vuid_manager_factory.node.spec.ts b/lib/vuid/vuid_manager_factory.node.spec.ts index 2a81f9a8a..048704794 100644 --- a/lib/vuid/vuid_manager_factory.node.spec.ts +++ b/lib/vuid/vuid_manager_factory.node.spec.ts @@ -17,10 +17,11 @@ import { vi, describe, expect, it } from 'vitest'; import { createVuidManager } from './vuid_manager_factory.node'; +import { VUID_IS_NOT_SUPPORTED_IN_NODEJS } from '../exception_messages'; describe('createVuidManager', () => { it('should throw an error', () => { expect(() => createVuidManager({ enableVuid: true })) - .toThrowError('VUID is not supported in Node.js environment'); + .toThrowError(VUID_IS_NOT_SUPPORTED_IN_NODEJS); }); }); diff --git a/lib/vuid/vuid_manager_factory.node.ts b/lib/vuid/vuid_manager_factory.node.ts index 993fbb60a..6d194ce0b 100644 --- a/lib/vuid/vuid_manager_factory.node.ts +++ b/lib/vuid/vuid_manager_factory.node.ts @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { VUID_IS_NOT_SUPPORTED_IN_NODEJS } from '../exception_messages'; import { VuidManager } from './vuid_manager'; import { VuidManagerOptions } from './vuid_manager_factory'; export const createVuidManager = (options: VuidManagerOptions): VuidManager => { - throw new Error('VUID is not supported in Node.js environment'); + throw new Error(VUID_IS_NOT_SUPPORTED_IN_NODEJS); };