@plyaz/core 1.8.4 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -577,6 +577,11 @@ export declare class Core {
577
577
  */
578
578
  /** Create and initialize root store (includes error store + all other slices) */
579
579
  private static initializeRootStore;
580
+ /**
581
+ * Serialize a PackageErrorLike to SerializedError format.
582
+ * Used by BaseError.setEventEmitter() to convert errors for the store.
583
+ */
584
+ private static serializePackageError;
580
585
  /** Get error store actions from root store */
581
586
  private static getErrorStoreActions;
582
587
  /** Build global error handler config */
@@ -589,9 +594,15 @@ export declare class Core {
589
594
  private static createHttpErrorHandler;
590
595
  /**
591
596
  * Subscribe to CoreEventManager error events
592
- * Forwards system, entity, API, validation, database, and auth errors to the global error handler.
597
+ * Forwards entity, API, validation, database, and auth errors to the global error handler.
598
+ *
599
+ * NOTE: SYSTEM.ERROR is NOT subscribed here - it's handled in initializeErrorHandler()
600
+ * via the BaseError.setEventEmitter() + addErrors() pattern to avoid duplicate subscriptions.
601
+ *
602
+ * For non-BaseError errors, domain-specific events (ENTITY.ERROR, API.REQUEST_ERROR, etc.)
603
+ * are captured here. BaseError instances are skipped (they already auto-emit via SYSTEM.ERROR).
593
604
  *
594
- * Note: Database errors (DATABASE.ERROR) are only subscribed on backend runtimes since
605
+ * Database errors (DATABASE.ERROR) are only subscribed on backend runtimes since
595
606
  * DbService is backend-only (skipDb: true on frontend).
596
607
  */
597
608
  private static subscribeToErrorEvents;
@@ -1 +1 @@
1
- {"version":3,"file":"CoreInitializer.d.ts","sourceRoot":"","sources":["../../src/init/CoreInitializer.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,KAAK,EACV,sBAAs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kF3C;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAiDrC,sDAAsD;IACtD,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAoBpC,kCAAkC;IAClC,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAmCjC;;OAEG;mBAGkB,sBAAsB;CAoC5C;AAID,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -25,6 +25,14 @@ var HEX_RADIX = 16;
25
25
  var HEX_SLICE_START = 2;
26
26
  var HEX_SLICE_END = 18;
27
27
  var SPAN_ID_LENGTH = 16;
28
+ function generateId() {
29
+ const cryptoApi = globalThis.crypto;
30
+ if (cryptoApi?.randomUUID) {
31
+ return cryptoApi.randomUUID();
32
+ }
33
+ return `${Date.now()}-${Math.random().toString(RANDOM_ID_RADIX).slice(RANDOM_ID_SLICE_START)}`;
34
+ }
35
+ __name(generateId, "generateId");
28
36
  function generateShortId() {
29
37
  const cryptoApi = globalThis.crypto;
30
38
  if (cryptoApi?.randomUUID) {
@@ -305,6 +313,80 @@ var ApiClientService = class _ApiClientService {
305
313
  static {
306
314
  this.initPromise = null;
307
315
  }
316
+ /**
317
+ * Build the core error handler for API clients.
318
+ * This handler emits errors to CoreEventManager for global error handling.
319
+ *
320
+ * Handles:
321
+ * - Single errors (network, timeout)
322
+ * - Array of errors from API responses (validation, business logic)
323
+ * - Serialization to unified SerializedError format
324
+ * - Event emission to CORE_EVENTS.SYSTEM.ERROR and CORE_EVENTS.API.REQUEST_ERROR
325
+ *
326
+ * @returns Error handler function compatible with ApiClientOptions.onError
327
+ */
328
+ static buildCoreErrorHandler() {
329
+ return async (error) => {
330
+ const requestId = errors.generateRequestId();
331
+ const method = error.config?.method ?? "UNKNOWN";
332
+ const url = error.config?.url ?? "unknown";
333
+ try {
334
+ const errorDetails = Array.isArray(error.response?.data) ? error.response.data : [];
335
+ if (errorDetails.length === 0) {
336
+ const serializedError = {
337
+ id: requestId,
338
+ code: types.ERROR_CODES.CORE_API_CLIENT_REQUEST_FAILED,
339
+ message: error.message ?? "API request failed",
340
+ status: error.status,
341
+ category: types.ERROR_CATEGORY.Network,
342
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
343
+ isRetryable: error.status ? error.status >= types.HTTP_STATUS.INTERNAL_SERVER_ERROR : false,
344
+ source: "api-client",
345
+ dismissed: false,
346
+ context: {
347
+ method,
348
+ url,
349
+ requestId
350
+ }
351
+ };
352
+ CoreEventManager.emit(types.CORE_EVENTS.SYSTEM.ERROR, { errors: [serializedError] });
353
+ } else {
354
+ const serializedErrors = errorDetails.map(
355
+ (detail, index) => ({
356
+ id: `${requestId}-${index}`,
357
+ code: detail.errorCode ?? types.ERROR_CODES.CORE_API_CLIENT_REQUEST_FAILED,
358
+ message: detail.message ?? error.message ?? "API request failed",
359
+ status: error.status,
360
+ category: types.ERROR_CATEGORY.Network,
361
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
362
+ isRetryable: error.status ? error.status >= types.HTTP_STATUS.INTERNAL_SERVER_ERROR : false,
363
+ source: "api-client",
364
+ dismissed: false,
365
+ context: {
366
+ method,
367
+ url,
368
+ requestId,
369
+ field: detail.field,
370
+ valueGiven: detail.valueGiven,
371
+ allowedValues: detail.allowedValues,
372
+ constraints: detail.constraints
373
+ }
374
+ })
375
+ );
376
+ CoreEventManager.emit(types.CORE_EVENTS.SYSTEM.ERROR, { errors: serializedErrors });
377
+ }
378
+ } catch (e) {
379
+ console.error("[ApiClientService] Failed to emit error event:", e);
380
+ }
381
+ _ApiClientService.emitApiError(error, {
382
+ method,
383
+ url,
384
+ requestId,
385
+ status: error.status,
386
+ duration: 0
387
+ });
388
+ };
389
+ }
308
390
  /**
309
391
  * Initialize the API client with environment config and API options
310
392
  *
@@ -342,71 +424,12 @@ var ApiClientService = class _ApiClientService {
342
424
  * 2. Environment metadata (envConfig - apiKey)
343
425
  * 3. API configuration (apiConfig - baseURL, encryption, timeout, etc.)
344
426
  */
345
- // eslint-disable-next-line max-lines-per-function, complexity
427
+ // eslint-disable-next-line complexity
346
428
  static async createClient(envConfig, apiConfig) {
347
429
  try {
348
430
  const envDefaults = getConfigForEnvironment(envConfig.env);
349
431
  const envMetadataMapped = mapEnvironmentMetadata(envConfig, envDefaults);
350
- const coreErrorHandler = /* @__PURE__ */ __name(async (error) => {
351
- const requestId = errors.generateRequestId();
352
- const method = error.config?.method ?? "UNKNOWN";
353
- const url = error.config?.url ?? "unknown";
354
- try {
355
- const errorDetails = Array.isArray(error.response?.data) ? error.response.data : [];
356
- if (errorDetails.length === 0) {
357
- const serializedError = {
358
- id: requestId,
359
- code: types.ERROR_CODES.CORE_API_CLIENT_REQUEST_FAILED,
360
- message: error.message ?? "API request failed",
361
- status: error.status,
362
- category: types.ERROR_CATEGORY.Network,
363
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
364
- isRetryable: error.status ? error.status >= types.HTTP_STATUS.INTERNAL_SERVER_ERROR : false,
365
- source: "api-client",
366
- dismissed: false,
367
- context: {
368
- method,
369
- url,
370
- requestId
371
- }
372
- };
373
- CoreEventManager.emit(types.CORE_EVENTS.SYSTEM.ERROR, { errors: [serializedError] });
374
- } else {
375
- const serializedErrors = errorDetails.map(
376
- (detail, index) => ({
377
- id: `${requestId}-${index}`,
378
- code: detail.errorCode ?? types.ERROR_CODES.CORE_API_CLIENT_REQUEST_FAILED,
379
- message: detail.message ?? error.message ?? "API request failed",
380
- status: error.status,
381
- category: types.ERROR_CATEGORY.Network,
382
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
383
- isRetryable: error.status ? error.status >= types.HTTP_STATUS.INTERNAL_SERVER_ERROR : false,
384
- source: "api-client",
385
- dismissed: false,
386
- context: {
387
- method,
388
- url,
389
- requestId,
390
- field: detail.field,
391
- valueGiven: detail.valueGiven,
392
- allowedValues: detail.allowedValues,
393
- constraints: detail.constraints
394
- }
395
- })
396
- );
397
- CoreEventManager.emit(types.CORE_EVENTS.SYSTEM.ERROR, { errors: serializedErrors });
398
- }
399
- } catch (e) {
400
- console.error("[ApiClientService] Failed to emit error event:", e);
401
- }
402
- _ApiClientService.emitApiError(error, {
403
- method,
404
- url,
405
- requestId,
406
- status: error.status,
407
- duration: 0
408
- });
409
- }, "coreErrorHandler");
432
+ const coreErrorHandler = _ApiClientService.buildCoreErrorHandler();
410
433
  const userOnError = apiConfig?.onError;
411
434
  const combinedOnError = userOnError ? Array.isArray(userOnError) ? [...userOnError, coreErrorHandler] : [userOnError, coreErrorHandler] : coreErrorHandler;
412
435
  const mergedOptions = frontend.mergeConfigs(
@@ -581,11 +604,13 @@ var ApiClientService = class _ApiClientService {
581
604
  try {
582
605
  const envDefaults = getConfigForEnvironment(envConfig.env);
583
606
  const envMetadataMapped = mapEnvironmentMetadata(envConfig, envDefaults);
584
- const mergedOptions = frontend.mergeConfigs(
585
- envDefaults,
586
- envMetadataMapped,
587
- apiConfig ?? {}
588
- );
607
+ const coreErrorHandler = _ApiClientService.buildCoreErrorHandler();
608
+ const userOnError = apiConfig?.onError;
609
+ const combinedOnError = userOnError ? Array.isArray(userOnError) ? [...userOnError, coreErrorHandler] : [userOnError, coreErrorHandler] : coreErrorHandler;
610
+ const mergedOptions = frontend.mergeConfigs(envDefaults, envMetadataMapped, {
611
+ ...apiConfig ?? {},
612
+ onError: combinedOnError
613
+ });
589
614
  validateEnvironmentConfig(envConfig, mergedOptions);
590
615
  const dedicatedClient = await frontend.createApiClient(mergedOptions);
591
616
  return dedicatedClient;
@@ -607,6 +632,61 @@ var ApiClientService = class _ApiClientService {
607
632
  );
608
633
  }
609
634
  }
635
+ /**
636
+ * Create a standalone API client with Core error handling.
637
+ *
638
+ * This is a simpler alternative to `createInstance()` that doesn't require
639
+ * environment config. Use this when you just need the error handling without
640
+ * environment-specific defaults (production validation, etc.).
641
+ *
642
+ * **Use cases:**
643
+ * - Domain services that need their own API client
644
+ * - Testing with isolated API clients
645
+ * - Simple client creation without environment setup
646
+ *
647
+ * @param apiConfig - API configuration (baseURL, timeout, etc.)
648
+ * @returns Promise that resolves to a client with Core error handling
649
+ *
650
+ * @example
651
+ * ```typescript
652
+ * // In BaseDomainService or any service
653
+ * const client = await ApiClientService.createStandaloneClient({
654
+ * baseURL: '/api/examples',
655
+ * timeout: 10000,
656
+ * });
657
+ *
658
+ * // Errors are automatically emitted to CoreEventManager
659
+ * const response = await client.get('/items');
660
+ * ```
661
+ */
662
+ static async createStandaloneClient(apiConfig) {
663
+ try {
664
+ const coreErrorHandler = _ApiClientService.buildCoreErrorHandler();
665
+ const userOnError = apiConfig.onError;
666
+ const combinedOnError = userOnError ? Array.isArray(userOnError) ? [...userOnError, coreErrorHandler] : [userOnError, coreErrorHandler] : coreErrorHandler;
667
+ const client = await frontend.createApiClient({
668
+ ...apiConfig,
669
+ onError: combinedOnError
670
+ });
671
+ return client;
672
+ } catch (error) {
673
+ throw new frontend.ApiPackageError(
674
+ "service.standalone_client_creation.failed",
675
+ types.PACKAGE_STATUS_CODES.INITIALIZATION_FAILED,
676
+ types.API_ERROR_CODES.CLIENT_INITIALIZATION_FAILED,
677
+ {
678
+ cause: error instanceof Error ? error : void 0,
679
+ context: {
680
+ operation: types.OPERATIONS.INITIALIZATION,
681
+ originalError: error instanceof Error ? error.message : String(error),
682
+ i18n: {
683
+ error: error instanceof Error ? error.message : String(error)
684
+ }
685
+ }
686
+ }
687
+ );
688
+ }
689
+ }
610
690
  };
611
691
  var BaseAdapter = class {
612
692
  constructor() {
@@ -3163,6 +3243,7 @@ var Core = class _Core {
3163
3243
  _Core._errorHandler.destroy();
3164
3244
  _Core._errorHandler = null;
3165
3245
  middleware.clearEventEmitter();
3246
+ errors.BaseError.clearEventEmitter();
3166
3247
  }
3167
3248
  _Core._errorConfig = {};
3168
3249
  _Core._httpErrorHandler = null;
@@ -3351,6 +3432,28 @@ var Core = class _Core {
3351
3432
  };
3352
3433
  }
3353
3434
  }
3435
+ /**
3436
+ * Serialize a PackageErrorLike to SerializedError format.
3437
+ * Used by BaseError.setEventEmitter() to convert errors for the store.
3438
+ */
3439
+ static serializePackageError(error) {
3440
+ const serviceName = typeof error.context?.service === "string" ? error.context.service : "core";
3441
+ return {
3442
+ id: generateId(),
3443
+ code: error.errorCode ?? types.ERROR_CODES.UNKNOWN_ERROR,
3444
+ message: error.message,
3445
+ status: error.statusCode,
3446
+ category: error.category ?? errors$1.ERROR_CATEGORY.Server,
3447
+ timestamp: error.timestamp ?? (/* @__PURE__ */ new Date()).toISOString(),
3448
+ isRetryable: error.retryable ?? false,
3449
+ source: serviceName,
3450
+ dismissed: false,
3451
+ context: {
3452
+ correlationId: error.correlationId,
3453
+ ...error.context
3454
+ }
3455
+ };
3456
+ }
3354
3457
  /** Get error store actions from root store */
3355
3458
  static getErrorStoreActions() {
3356
3459
  if (!_Core._rootStore) {
@@ -3362,12 +3465,17 @@ var Core = class _Core {
3362
3465
  return _Core._rootStore.getState().errors;
3363
3466
  }
3364
3467
  /** Build global error handler config */
3365
- // eslint-disable-next-line complexity
3366
3468
  static buildErrorHandlerConfig(config) {
3469
+ const baseErrorFilter = /* @__PURE__ */ __name((error) => {
3470
+ if (error instanceof errors.BaseError) {
3471
+ return false;
3472
+ }
3473
+ return config?.filter ? config.filter(error) : true;
3474
+ }, "baseErrorFilter");
3367
3475
  return {
3368
3476
  source: config?.source ?? "global",
3369
3477
  maxErrors: config?.maxErrors ?? DEFAULT_MAX_ERRORS,
3370
- filter: config?.filter,
3478
+ filter: baseErrorFilter,
3371
3479
  onError: config?.onError,
3372
3480
  logToConsole: config?.logToConsole ?? false
3373
3481
  };
@@ -3388,6 +3496,15 @@ var Core = class _Core {
3388
3496
  });
3389
3497
  await _Core.initializeRootStore(_Core._errorConfig, verbose);
3390
3498
  middleware.setEventEmitter(CoreEventManager.emit.bind(CoreEventManager));
3499
+ errors.BaseError.setEventEmitter((error) => {
3500
+ const serializedError = _Core.serializePackageError(error);
3501
+ const serviceName = serializedError.source ?? "core";
3502
+ CoreEventManager.emit(core.CORE_EVENTS.SYSTEM.ERROR, {
3503
+ errors: [serializedError],
3504
+ context: serviceName,
3505
+ recoverable: error.retryable ?? false
3506
+ });
3507
+ });
3391
3508
  const errorStore = _Core.getErrorStoreActions();
3392
3509
  _Core._errorHandler = middleware.initializeGlobalErrorHandler(
3393
3510
  errorStore,
@@ -3483,9 +3600,15 @@ var Core = class _Core {
3483
3600
  }
3484
3601
  /**
3485
3602
  * Subscribe to CoreEventManager error events
3486
- * Forwards system, entity, API, validation, database, and auth errors to the global error handler.
3603
+ * Forwards entity, API, validation, database, and auth errors to the global error handler.
3604
+ *
3605
+ * NOTE: SYSTEM.ERROR is NOT subscribed here - it's handled in initializeErrorHandler()
3606
+ * via the BaseError.setEventEmitter() + addErrors() pattern to avoid duplicate subscriptions.
3607
+ *
3608
+ * For non-BaseError errors, domain-specific events (ENTITY.ERROR, API.REQUEST_ERROR, etc.)
3609
+ * are captured here. BaseError instances are skipped (they already auto-emit via SYSTEM.ERROR).
3487
3610
  *
3488
- * Note: Database errors (DATABASE.ERROR) are only subscribed on backend runtimes since
3611
+ * Database errors (DATABASE.ERROR) are only subscribed on backend runtimes since
3489
3612
  * DbService is backend-only (skipDb: true on frontend).
3490
3613
  */
3491
3614
  static subscribeToErrorEvents(verbose) {
@@ -3493,78 +3616,36 @@ var Core = class _Core {
3493
3616
  return;
3494
3617
  }
3495
3618
  _Core.log("Subscribing to error events...", verbose);
3496
- const cleanupSystemError = CoreEventManager.on(core.CORE_EVENTS.SYSTEM.ERROR, (event) => {
3497
- if (_Core._errorHandler && event.data?.errors?.length) {
3498
- for (const err of event.data.errors) {
3499
- _Core._errorHandler.captureError(err, "system");
3619
+ const subscribeError = /* @__PURE__ */ __name((event, source) => {
3620
+ return CoreEventManager.on(event, (e) => {
3621
+ if (_Core._errorHandler && e.data?.error && !(e.data.error instanceof errors.BaseError)) {
3622
+ _Core._errorHandler.captureError(e.data.error, source);
3500
3623
  }
3501
- }
3502
- });
3503
- const cleanupEntityError = CoreEventManager.on(core.CORE_EVENTS.ENTITY.ERROR, (event) => {
3504
- if (_Core._errorHandler && event.data) {
3505
- _Core._errorHandler.captureError(event.data.error, "entity");
3506
- }
3507
- });
3508
- const cleanupApiError = CoreEventManager.on(core.CORE_EVENTS.API.REQUEST_ERROR, (event) => {
3509
- if (_Core._errorHandler && event.data) {
3510
- _Core._errorHandler.captureError(event.data.error, "api");
3511
- }
3512
- });
3513
- const cleanupValidationError = CoreEventManager.on(core.CORE_EVENTS.VALIDATION.FAILED, (event) => {
3514
- if (_Core._errorHandler && event.data) {
3515
- _Core._errorHandler.captureError(event.data.error, "validation");
3516
- }
3517
- });
3518
- const cleanupAuthUnauthorized = CoreEventManager.on(core.CORE_EVENTS.AUTH.UNAUTHORIZED, (event) => {
3519
- if (_Core._errorHandler && event.data?.error) {
3520
- _Core._errorHandler.captureError(event.data.error, "auth");
3521
- }
3522
- });
3523
- const cleanupAuthSessionExpired = CoreEventManager.on(
3524
- core.CORE_EVENTS.AUTH.SESSION_EXPIRED,
3525
- (event) => {
3526
- if (_Core._errorHandler && event.data?.error) {
3527
- _Core._errorHandler.captureError(event.data.error, "auth");
3528
- }
3529
- }
3530
- );
3624
+ });
3625
+ }, "subscribeError");
3531
3626
  _Core._eventCleanupFns.push(
3532
- cleanupSystemError,
3533
- cleanupEntityError,
3534
- cleanupApiError,
3535
- cleanupValidationError,
3536
- cleanupAuthUnauthorized,
3537
- cleanupAuthSessionExpired
3627
+ subscribeError(core.CORE_EVENTS.ENTITY.ERROR, "entity"),
3628
+ subscribeError(core.CORE_EVENTS.API.REQUEST_ERROR, "api"),
3629
+ subscribeError(core.CORE_EVENTS.VALIDATION.FAILED, "validation"),
3630
+ subscribeError(core.CORE_EVENTS.AUTH.UNAUTHORIZED, "auth"),
3631
+ subscribeError(core.CORE_EVENTS.AUTH.SESSION_EXPIRED, "auth")
3538
3632
  );
3539
3633
  if (_Core.isRuntimeCompatible("backend")) {
3540
- const cleanupDatabaseError = CoreEventManager.on(core.CORE_EVENTS.DATABASE.ERROR, (event) => {
3541
- if (_Core._errorHandler && event.data) {
3542
- _Core._errorHandler.captureError(event.data.error, "database");
3543
- }
3544
- });
3545
- _Core._eventCleanupFns.push(cleanupDatabaseError);
3546
- const cleanupStorageError = CoreEventManager.on(core.CORE_EVENTS.STORAGE.ERROR, (event) => {
3547
- if (_Core._errorHandler && event.data) {
3548
- _Core._errorHandler.captureError(event.data.error, "storage");
3549
- }
3550
- });
3551
- _Core._eventCleanupFns.push(cleanupStorageError);
3552
- const cleanupNotificationError = CoreEventManager.on(
3553
- core.CORE_EVENTS.NOTIFICATION.ERROR,
3554
- (event) => {
3555
- if (_Core._errorHandler && event.data) {
3556
- _Core._errorHandler.captureError(event.data.error, "notification");
3557
- }
3558
- }
3634
+ _Core._eventCleanupFns.push(
3635
+ subscribeError(core.CORE_EVENTS.DATABASE.ERROR, "database"),
3636
+ subscribeError(core.CORE_EVENTS.STORAGE.ERROR, "storage"),
3637
+ subscribeError(core.CORE_EVENTS.NOTIFICATION.ERROR, "notification"),
3638
+ subscribeError(core.CORE_EVENTS.CACHE.ERROR, "cache")
3639
+ );
3640
+ _Core.log(
3641
+ "Subscribed to backend error events (database, storage, notification, cache)",
3642
+ verbose
3559
3643
  );
3560
- _Core._eventCleanupFns.push(cleanupNotificationError);
3561
- _Core.log("Subscribed to backend error events (database, storage, notification)", verbose);
3562
- }
3563
- const eventTypes = ["system", "entity", "api", "validation", "auth"];
3564
- if (_Core.isRuntimeCompatible("backend")) {
3565
- eventTypes.push("database", "storage", "notification");
3566
3644
  }
3567
- _Core.log(`Subscribed to error events: ${eventTypes.join(", ")}`, verbose);
3645
+ const eventTypes = ["entity", "api", "validation", "auth"];
3646
+ if (_Core.isRuntimeCompatible("backend"))
3647
+ eventTypes.push("database", "storage", "notification", "cache");
3648
+ _Core.log(`Subscribed to domain error events: ${eventTypes.join(", ")}`, verbose);
3568
3649
  }
3569
3650
  /** Handle fetch flags error and return empty flags */
3570
3651
  static handleFetchFlagsError(error, config, verbose) {