@@ -28,7 +28,7 @@ import {
2828 RC_CUSTOM_SIGNAL_KEY_MAX_LENGTH ,
2929 RC_CUSTOM_SIGNAL_VALUE_MAX_LENGTH
3030} from './constants' ;
31- import { ERROR_FACTORY , ErrorCode , hasErrorCode } from './errors' ;
31+ import { ErrorCode , hasErrorCode } from './errors' ;
3232import { RemoteConfig as RemoteConfigImpl } from './remote_config' ;
3333import { Value as ValueImpl } from './value' ;
3434import { LogLevel as FirebaseLogLevel } from '@firebase/logger' ;
@@ -270,8 +270,8 @@ function getAllKeys(obj1: {} = {}, obj2: {} = {}): string[] {
270270 *
271271 * @param remoteConfig - The {@link RemoteConfig} instance.
272272 * @param customSignals - Map (key, value) of the custom signals to be set for the app instance. If
273- * a key already exists, the value is overwritten. Setting the value of a custom signal null unsets
274- * the signal. The signals will be persisted locally on the client.
273+ * a key already exists, the value is overwritten. Setting the value of a custom signal to null
274+ * unsets the signal. The signals will be persisted locally on the client.
275275 *
276276 * @public
277277 */
@@ -280,25 +280,35 @@ export async function setCustomSignals(
280280 customSignals : CustomSignals
281281) : Promise < void > {
282282 const rc = getModularInstance ( remoteConfig ) as RemoteConfigImpl ;
283+ if ( Object . keys ( customSignals ) . length === 0 ) {
284+ return ;
285+ }
286+
283287 // eslint-disable-next-line guard-for-in
284288 for ( const key in customSignals ) {
285289 if ( key . length > RC_CUSTOM_SIGNAL_KEY_MAX_LENGTH ) {
286- throw ERROR_FACTORY . create ( ErrorCode . CUSTOM_SIGNAL_KEY_LENGTH , {
287- key,
288- maxLength : RC_CUSTOM_SIGNAL_KEY_MAX_LENGTH
289- } ) ;
290+ rc . _logger . error (
291+ `Custom signal key ${ key } is too long, max allowed length is ${ RC_CUSTOM_SIGNAL_KEY_MAX_LENGTH } .`
292+ ) ;
293+ return ;
290294 }
291295 const value = customSignals [ key ] ;
292296 if (
293297 typeof value === 'string' &&
294298 value . length > RC_CUSTOM_SIGNAL_VALUE_MAX_LENGTH
295299 ) {
296- throw ERROR_FACTORY . create ( ErrorCode . CUSTOM_SIGNAL_VALUE_LENGTH , {
297- key,
298- maxLength : RC_CUSTOM_SIGNAL_VALUE_MAX_LENGTH
299- } ) ;
300+ rc . _logger . error (
301+ `Value supplied for custom signal ${ key } is too long, max allowed length is ${ RC_CUSTOM_SIGNAL_VALUE_MAX_LENGTH } .`
302+ ) ;
303+ return ;
300304 }
301305 }
302306
303- return rc . _storageCache . setCustomSignals ( customSignals ) ;
307+ try {
308+ await rc . _storageCache . setCustomSignals ( customSignals ) ;
309+ } catch ( error ) {
310+ rc . _logger . error (
311+ `Error encountered while setting custom signals: ${ error } `
312+ ) ;
313+ }
304314}
0 commit comments