• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alkem-io / client-web / #9438

22 Nov 2024 11:19PM UTC coverage: 5.94%. First build
#9438

Pull #7248

travis-ci

Pull Request #7248: Fix build:dev (styled err)

208 of 10567 branches covered (1.97%)

Branch coverage included in aggregate %.

0 of 88 new or added lines in 14 files covered. (0.0%)

1501 of 18203 relevant lines covered (8.25%)

0.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/core/lazyLoading/lazyWithGlobalErrorHandler.ts
1
import React, { ComponentType } from 'react';
2
import { getGlobalErrorSetter } from './GlobalErrorContext';
3

4
type ImportFunc<T> = () => Promise<{ default: React.ComponentType<T> }>;
5

6
export class LazyLoadError extends Error {
7
  constructor(originalError: Error) {
NEW
8
    super(originalError.message);
×
NEW
9
    this.name = 'LazyLoadError';
×
NEW
10
    Object.setPrototypeOf(this, LazyLoadError.prototype);
×
11
  }
12
}
13

NEW
14
export const lazyWithGlobalErrorHandler = <T extends object>(
×
15
  importFunc: ImportFunc<T>,
16
  hoc?: (component: ComponentType<T>) => ComponentType<T>
NEW
17
): React.LazyExoticComponent<React.ComponentType<T>> => {
×
NEW
18
  return React.lazy(async () => {
×
NEW
19
    try {
×
20
      const module = await importFunc();
NEW
21
      const Component = module.default;
×
22
      return { default: hoc ? hoc(Component) : Component };
NEW
23
    } catch (error) {
×
24
      const setError = getGlobalErrorSetter();
NEW
25
      const originalError: Error =
×
26
        error instanceof Error ? error : error?.['message'] ? new Error(error['message']) : new Error('Unknown error');
27

28
      setError(new LazyLoadError(originalError));
29

30
      // it looks like this error is already logged by the useErrorLoggerLink (network error)
NEW
31

×
NEW
32
      // Instead of throwing, return a fallback component to prevent
×
33
      // catching it in the ErrorBoundary
34
      return {
35
        default: () => null,
36
      };
37
    }
NEW
38
  });
×
NEW
39
};
×
NEW
40

×
41
export const lazyImportWithErrorHandler = async <T>(importFunc: () => Promise<T>): Promise<T> => {
NEW
42
  try {
×
43
    return await importFunc();
NEW
44
  } catch (error) {
×
45
    const setError = getGlobalErrorSetter();
NEW
46
    const originalError: Error =
×
NEW
47
      error instanceof Error ? error : error?.['message'] ? new Error(error['message']) : new Error('Unknown error');
×
48

49
    setError(new LazyLoadError(originalError));
50
    throw new LazyLoadError(originalError);
51
  }
52
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc