@xyo-network/react-error 4.1.8 → 4.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. package/dist/browser/components/ErrorBoundary/ThrownErrorBoundary.d.ts +3 -15
  2. package/dist/browser/components/ErrorBoundary/ThrownErrorBoundary.d.ts.map +1 -1
  3. package/dist/browser/components/ErrorBoundary/ThrownErrorBoundaryBase.d.ts +21 -0
  4. package/dist/browser/components/ErrorBoundary/ThrownErrorBoundaryBase.d.ts.map +1 -0
  5. package/dist/browser/components/ErrorBoundary.d.ts +3 -0
  6. package/dist/browser/components/ErrorBoundary.d.ts.map +1 -1
  7. package/dist/browser/components/ErrorRender/ErrorAlert.d.ts +3 -5
  8. package/dist/browser/components/ErrorRender/ErrorAlert.d.ts.map +1 -1
  9. package/dist/browser/components/ErrorRender/Props.d.ts +3 -3
  10. package/dist/browser/components/ErrorRender/Props.d.ts.map +1 -1
  11. package/dist/browser/components/ErrorRender/Render.d.ts +1 -2
  12. package/dist/browser/components/ErrorRender/Render.d.ts.map +1 -1
  13. package/dist/browser/contexts/ErrorReporter/Context.d.ts +1 -0
  14. package/dist/browser/contexts/ErrorReporter/Context.d.ts.map +1 -1
  15. package/dist/browser/contexts/ErrorReporter/Provider.d.ts +4 -3
  16. package/dist/browser/contexts/ErrorReporter/Provider.d.ts.map +1 -1
  17. package/dist/browser/contexts/ErrorReporter/State.d.ts +1 -0
  18. package/dist/browser/contexts/ErrorReporter/State.d.ts.map +1 -1
  19. package/dist/browser/contexts/ErrorReporter/useErrorReporter.d.ts +1 -0
  20. package/dist/browser/contexts/ErrorReporter/useErrorReporter.d.ts.map +1 -1
  21. package/dist/browser/index.mjs +41 -97
  22. package/dist/browser/index.mjs.map +1 -1
  23. package/package.json +5 -5
  24. package/src/components/ErrorBoundary/ThrownErrorBoundary.tsx +6 -76
  25. package/src/components/ErrorBoundary/ThrownErrorBoundaryBase.tsx +77 -0
  26. package/src/components/ErrorBoundary.tsx +3 -0
  27. package/src/components/ErrorRender/ErrorAlert.tsx +5 -6
  28. package/src/components/ErrorRender/Props.ts +4 -3
  29. package/src/components/ErrorRender/Render.tsx +2 -2
  30. package/src/contexts/ErrorReporter/Context.ts +1 -0
  31. package/src/contexts/ErrorReporter/Provider.tsx +4 -5
  32. package/src/contexts/ErrorReporter/State.ts +1 -0
  33. package/src/contexts/ErrorReporter/useErrorReporter.tsx +1 -0
@@ -1,17 +1,5 @@
1
+ import type { ThrownErrorBoundaryProps } from '@xylabs/react-error';
1
2
  import type { ModuleError } from '@xyo-network/payload-model';
2
- import type { FC, ReactNode } from 'react';
3
- import type Rollbar from 'rollbar';
4
- export interface ThrownErrorBoundaryProps {
5
- boundaryName?: string;
6
- children: ReactNode;
7
- errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode;
8
- rethrow?: boolean;
9
- rollbar?: Rollbar;
10
- scope?: string;
11
- title?: string;
12
- }
13
- export interface ThrownErrorBoundaryState {
14
- xyoError?: ModuleError;
15
- }
16
- export declare const ThrownErrorBoundary: FC<ThrownErrorBoundaryProps>;
3
+ import type { FC } from 'react';
4
+ export declare const ThrownErrorBoundary: FC<ThrownErrorBoundaryProps<ModuleError>>;
17
5
  //# sourceMappingURL=ThrownErrorBoundary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ThrownErrorBoundary.d.ts","sourceRoot":"","sources":["../../../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAE7D,OAAO,KAAK,EACC,EAAE,EAAE,SAAS,EACzB,MAAM,OAAO,CAAA;AAEd,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAKlC,MAAM,WAAW,wBAAwB;IACvC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,SAAS,CAAA;IACnB,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,SAAS,CAAA;IACrE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,WAAW,CAAA;CACvB;AA+CD,eAAO,MAAM,mBAAmB,EAAE,EAAE,CAAC,wBAAwB,CAQ5D,CAAA"}
1
+ {"version":3,"file":"ThrownErrorBoundary.d.ts","sourceRoot":"","sources":["../../../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAA;AAI/B,eAAO,MAAM,mBAAmB,EAAE,EAAE,CAAC,wBAAwB,CAAC,WAAW,CAAC,CAEzE,CAAA"}
@@ -0,0 +1,21 @@
1
+ import type { ReactNode } from 'react';
2
+ import type Rollbar from 'rollbar';
3
+ /** @deprecated use from @xylabs/react-error instead */
4
+ export type ErrorEx<T = void> = T extends void ? Error : T | Error;
5
+ /** @deprecated use from @xylabs/react-error instead */
6
+ export interface ThrownErrorBoundaryProps<T = void> {
7
+ boundaryName?: string;
8
+ children: ReactNode;
9
+ errorComponent?: (e: ErrorEx<T>, boundaryName?: string) => ReactNode;
10
+ rethrow?: boolean;
11
+ rollbar?: Rollbar;
12
+ scope?: string;
13
+ title?: string;
14
+ }
15
+ /** @deprecated use from @xylabs/react-error instead */
16
+ export interface ThrownErrorBoundaryState<T = void> {
17
+ errorEx?: ErrorEx<T>;
18
+ }
19
+ /** @deprecated use from @xylabs/react-error instead */
20
+ export declare function ThrownErrorBoundaryBase<T = void>({ rollbar, ...props }: ThrownErrorBoundaryProps<T>): JSX.Element;
21
+ //# sourceMappingURL=ThrownErrorBoundaryBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThrownErrorBoundaryBase.d.ts","sourceRoot":"","sources":["../../../../src/components/ErrorBoundary/ThrownErrorBoundaryBase.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjD,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAKlC,uDAAuD;AACvD,MAAM,MAAM,OAAO,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,CAAA;AAElE,uDAAuD;AACvD,MAAM,WAAW,wBAAwB,CAAC,CAAC,GAAG,IAAI;IAChD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,SAAS,CAAA;IACnB,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,SAAS,CAAA;IACpE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,uDAAuD;AACvD,MAAM,WAAW,wBAAwB,CAAC,CAAC,GAAG,IAAI;IAChD,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;CACrB;AA0CD,uDAAuD;AACvD,wBAAgB,uBAAuB,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,wBAAwB,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CAQjH"}
@@ -1,14 +1,17 @@
1
1
  import type { ErrorInfo, ReactNode } from 'react';
2
2
  import { Component } from 'react';
3
+ /** @deprecated use from @xylabs/react-error instead */
3
4
  export interface ErrorBoundaryProps {
4
5
  children: ReactNode;
5
6
  fallback?: ReactNode;
6
7
  fallbackWithError?: (error: Error) => ReactNode;
7
8
  scope?: string;
8
9
  }
10
+ /** @deprecated use from @xylabs/react-error instead */
9
11
  export interface ErrorBoundaryState {
10
12
  error?: Error;
11
13
  }
14
+ /** @deprecated use from @xylabs/react-error instead */
12
15
  export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
13
16
  constructor(props: ErrorBoundaryProps);
14
17
  static getDerivedStateFromError(error: Error): {
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/ErrorBoundary.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjD,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAExC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,SAAS,CAAA;IAEnB,QAAQ,CAAC,EAAE,SAAS,CAAA;IAEpB,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,CAAA;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,KAAK,CAAA;CACd;AAED,qBAAa,aAAc,SAAQ,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;gBACtE,KAAK,EAAE,kBAAkB;IAKrC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK;;;IAInC,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS;IAIpD,MAAM;CA4BhB"}
1
+ {"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/ErrorBoundary.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjD,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAExC,uDAAuD;AACvD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,SAAS,CAAA;IAEnB,QAAQ,CAAC,EAAE,SAAS,CAAA;IAEpB,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,SAAS,CAAA;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,uDAAuD;AACvD,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,KAAK,CAAA;CACd;AAED,uDAAuD;AACvD,qBAAa,aAAc,SAAQ,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;gBACtE,KAAK,EAAE,kBAAkB;IAKrC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK;;;IAInC,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS;IAIpD,MAAM;CA4BhB"}
@@ -1,12 +1,10 @@
1
1
  import type { AlertProps } from '@mui/material';
2
- import type { ModuleError } from '@xyo-network/payload-model';
3
- import React from 'react';
4
- export interface ErrorAlertProps extends AlertProps {
5
- error?: ModuleError | Error | string;
2
+ export interface ErrorAlertProps<T = void> extends AlertProps {
3
+ error?: T | Error | string;
6
4
  /** @deprecated use scope instead */
7
5
  errorContext?: string;
8
6
  onCancel?: () => void;
9
7
  scope?: string;
10
8
  }
11
- export declare const ErrorAlert: React.FC<ErrorAlertProps>;
9
+ export declare function ErrorAlert<T = void>({ title, onCancel, error, errorContext, scope, ...props }: ErrorAlertProps<T>): JSX.Element;
12
10
  //# sourceMappingURL=ErrorAlert.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorAlert.d.ts","sourceRoot":"","sources":["../../../../src/components/ErrorRender/ErrorAlert.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAK/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,WAAW,eAAgB,SAAQ,UAAU;IACjD,KAAK,CAAC,EAAE,WAAW,GAAG,KAAK,GAAG,MAAM,CAAA;IACpC,oCAAoC;IACpC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA2ChD,CAAA"}
1
+ {"version":3,"file":"ErrorAlert.d.ts","sourceRoot":"","sources":["../../../../src/components/ErrorRender/ErrorAlert.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAO/C,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,IAAI,CAAE,SAAQ,UAAU;IAC3D,KAAK,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,MAAM,CAAA;IAC1B,oCAAoC;IACpC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,wBAAgB,UAAU,CAAC,CAAC,GAAG,IAAI,EAAE,EACnC,KAAsC,EACtC,QAAQ,EACR,KAAmC,EACnC,YAAY,EACZ,KAAK,EACL,GAAG,KAAK,EACT,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CAoClC"}
@@ -1,10 +1,10 @@
1
1
  import type { FlexBoxProps } from '@xylabs/react-flexbox';
2
- import type { ModuleError } from '@xyo-network/payload-model';
3
2
  import type { ReactNode } from 'react';
4
3
  import type { Location } from 'react-router-dom';
5
- export interface ErrorRenderProps extends FlexBoxProps {
4
+ export type ErrorEx<T = void> = T extends void ? Error : T | Error;
5
+ export interface ErrorRenderProps<T = void> extends FlexBoxProps {
6
6
  customError?: ReactNode;
7
- error?: ModuleError | Error;
7
+ error?: ErrorEx<T>;
8
8
  errorContext?: string;
9
9
  noErrorDisplay?: boolean;
10
10
  noReAuth?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"Props.d.ts","sourceRoot":"","sources":["../../../../src/components/ErrorRender/Props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAEhD,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,KAAK,CAAC,EAAE,WAAW,GAAG,KAAK,CAAA;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,QAAQ,CAAA;CAC7B"}
1
+ {"version":3,"file":"Props.d.ts","sourceRoot":"","sources":["../../../../src/components/ErrorRender/Props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAEhD,MAAM,MAAM,OAAO,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,CAAA;AAElE,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,IAAI,CAAE,SAAQ,YAAY;IAC9D,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IAClB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,QAAQ,CAAA;CAC7B"}
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import type { ErrorRenderProps } from './Props.ts';
3
- export declare const ErrorRender: React.FC<ErrorRenderProps>;
2
+ export declare function ErrorRender<T = void>({ onCancel, error, noErrorDisplay, customError, children, errorContext, scope, useLocation, ...props }: ErrorRenderProps<T>): JSX.Element;
4
3
  //# sourceMappingURL=Render.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Render.d.ts","sourceRoot":"","sources":["../../../../src/components/ErrorRender/Render.tsx"],"names":[],"mappings":"AACA,OAAO,KAAoB,MAAM,OAAO,CAAA;AAGxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAsClD,CAAA"}
1
+ {"version":3,"file":"Render.d.ts","sourceRoot":"","sources":["../../../../src/components/ErrorRender/Render.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,wBAAgB,WAAW,CAAC,CAAC,GAAG,IAAI,EAAE,EACpC,QAAQ,EACR,KAAK,EACL,cAAsB,EACtB,WAAkB,EAClB,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,WAAW,EACX,GAAG,KAAK,EACT,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CA4BnC"}
@@ -1,3 +1,4 @@
1
1
  import type { ErrorReporterContextState } from './State.ts';
2
+ /** @deprecated use from @xylabs/react-error instead */
2
3
  export declare const ErrorReporterContext: import("react").Context<ErrorReporterContextState>;
3
4
  //# sourceMappingURL=Context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../../src/contexts/ErrorReporter/Context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAE3D,eAAO,MAAM,oBAAoB,oDAA+C,CAAA"}
1
+ {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../../../src/contexts/ErrorReporter/Context.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAE3D,uDAAuD;AACvD,eAAO,MAAM,oBAAoB,oDAA+C,CAAA"}
@@ -1,9 +1,10 @@
1
- import type { WithChildren } from '@xylabs/react-shared';
1
+ import type { PropsWithChildren } from 'react';
2
2
  import React from 'react';
3
3
  import type Rollbar from 'rollbar';
4
+ /** @deprecated use from @xylabs/react-error instead */
4
5
  export interface ErrorReporterProviderProps {
5
6
  rollbar: Rollbar;
6
7
  }
7
- declare const ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>>;
8
- export { ErrorReporterProvider };
8
+ /** @deprecated use from @xylabs/react-error instead */
9
+ export declare const ErrorReporterProvider: React.FC<PropsWithChildren<ErrorReporterProviderProps>>;
9
10
  //# sourceMappingURL=Provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/ErrorReporter/Provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAIlC,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,QAAA,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,0BAA0B,CAAC,CAe7E,CAAA;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAA"}
1
+ {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../src/contexts/ErrorReporter/Provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAC9C,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAIlC,uDAAuD;AACvD,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,OAAO,CAAA;CACjB;AACD,uDAAuD;AACvD,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,0BAA0B,CAAC,CAezF,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import type Rollbar from 'rollbar';
2
+ /** @deprecated use from @xylabs/react-error instead */
2
3
  export interface ErrorReporterContextState {
3
4
  rollbar?: Rollbar;
4
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/contexts/ErrorReporter/State.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAElC,MAAM,WAAW,yBAAyB;IACxC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB"}
1
+ {"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../../../src/contexts/ErrorReporter/State.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAElC,uDAAuD;AACvD,MAAM,WAAW,yBAAyB;IACxC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB"}
@@ -1,2 +1,3 @@
1
+ /** @deprecated use from @xylabs/react-error instead */
1
2
  export declare const useErrorReporter: () => import("./State.ts").ErrorReporterContextState;
2
3
  //# sourceMappingURL=useErrorReporter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useErrorReporter.d.ts","sourceRoot":"","sources":["../../../../src/contexts/ErrorReporter/useErrorReporter.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,gBAAgB,sDAO5B,CAAA"}
1
+ {"version":3,"file":"useErrorReporter.d.ts","sourceRoot":"","sources":["../../../../src/contexts/ErrorReporter/useErrorReporter.tsx"],"names":[],"mappings":"AAIA,uDAAuD;AACvD,eAAO,MAAM,gBAAgB,sDAO5B,CAAA"}
@@ -41,52 +41,18 @@ var ErrorBoundary = class extends Component {
41
41
  };
42
42
 
43
43
  // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
44
- import { useRollbar as useRollbar2 } from "@rollbar/react";
45
- import { ModuleErrorSchema } from "@xyo-network/payload-model";
46
- import React5, { Component as Component2 } from "react";
47
-
48
- // src/contexts/ErrorReporter/Provider.tsx
49
- import { useRollbar } from "@rollbar/react";
44
+ import { ThrownErrorBoundary as ThrownErrorBoundaryBase } from "@xylabs/react-error";
50
45
  import React2 from "react";
51
-
52
- // src/contexts/ErrorReporter/Context.ts
53
- import { createContext } from "react";
54
- var ErrorReporterContext = createContext({});
55
-
56
- // src/contexts/ErrorReporter/Provider.tsx
57
- var ErrorReporterProvider = /* @__PURE__ */ __name(({ children, rollbar: rollbarProp }) => {
58
- let rollbarFromHook;
59
- try {
60
- rollbarFromHook = useRollbar();
61
- } catch {
62
- }
63
- const rollbar = rollbarProp ?? rollbarFromHook;
64
- if (!rollbar) {
65
- throw new Error("ErrorReporterProvider unable to find a Rollbar instance either passed as prop or from Provider");
66
- }
67
- return /* @__PURE__ */ React2.createElement(ErrorReporterContext.Provider, {
68
- value: {
69
- rollbar
70
- }
71
- }, children);
72
- }, "ErrorReporterProvider");
73
-
74
- // src/contexts/ErrorReporter/useErrorReporter.tsx
75
- import { useContext } from "react";
76
- var useErrorReporter = /* @__PURE__ */ __name(() => {
77
- const context = useContext(ErrorReporterContext);
78
- if (context === void 0) {
79
- console.warn("useErrorReporter must be used within a ErrorReporterContext");
80
- }
81
- return context ?? {};
82
- }, "useErrorReporter");
46
+ var ThrownErrorBoundary = /* @__PURE__ */ __name((props) => {
47
+ return /* @__PURE__ */ React2.createElement(ThrownErrorBoundaryBase, props);
48
+ }, "ThrownErrorBoundary");
83
49
 
84
50
  // src/components/ErrorRender/ErrorAlert.tsx
85
51
  import { ExitToApp as ExitIcon } from "@mui/icons-material";
86
52
  import { Alert, AlertTitle, Typography as Typography2 } from "@mui/material";
87
53
  import { ButtonEx } from "@xylabs/react-button";
88
54
  import React3 from "react";
89
- var ErrorAlert = /* @__PURE__ */ __name(({ title = "Whoops! Something went wrong", onCancel, error = "An unknown error occurred", errorContext, scope, ...props }) => {
55
+ function ErrorAlert({ title = "Whoops! Something went wrong", onCancel, error = "An unknown error occurred", errorContext, scope, ...props }) {
90
56
  const finalScope = scope ?? errorContext;
91
57
  return /* @__PURE__ */ React3.createElement(Alert, {
92
58
  severity: "error",
@@ -115,12 +81,13 @@ var ErrorAlert = /* @__PURE__ */ __name(({ title = "Whoops! Something went wrong
115
81
  }, /* @__PURE__ */ React3.createElement(ExitIcon, {
116
82
  fontSize: "small"
117
83
  })) : null);
118
- }, "ErrorAlert");
84
+ }
85
+ __name(ErrorAlert, "ErrorAlert");
119
86
 
120
87
  // src/components/ErrorRender/Render.tsx
121
88
  import { FlexCol as FlexCol2 } from "@xylabs/react-flexbox";
122
89
  import React4, { useEffect } from "react";
123
- var ErrorRender = /* @__PURE__ */ __name(({ onCancel, error, noErrorDisplay = false, customError = null, children, errorContext, scope, useLocation, ...props }) => {
90
+ function ErrorRender({ onCancel, error, noErrorDisplay = false, customError = null, children, errorContext, scope, useLocation, ...props }) {
124
91
  const location = useLocation?.();
125
92
  useEffect(() => {
126
93
  if (location) {
@@ -152,67 +119,44 @@ var ErrorRender = /* @__PURE__ */ __name(({ onCancel, error, noErrorDisplay = fa
152
119
  onCancel,
153
120
  scope
154
121
  }))) : /* @__PURE__ */ React4.createElement(React4.Fragment, null, children);
155
- }, "ErrorRender");
122
+ }
123
+ __name(ErrorRender, "ErrorRender");
156
124
 
157
- // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
158
- var ThrownErrorBoundaryInner = class ThrownErrorBoundaryInner2 extends Component2 {
159
- static {
160
- __name(this, "ThrownErrorBoundaryInner");
161
- }
162
- state = {
163
- xyoError: void 0
164
- };
165
- static getDerivedStateFromError(error) {
166
- return {
167
- hasError: true,
168
- xyoError: ThrownErrorBoundaryInner2.normalizeError(error)
169
- };
170
- }
171
- static normalizeError(error) {
172
- return error.schema === ModuleErrorSchema ? error : {
173
- message: error.message,
174
- schema: ModuleErrorSchema,
175
- sources: []
176
- };
177
- }
178
- componentDidCatch(error, errorInfo) {
179
- const { rethrow, rollbar } = this.props;
180
- const { xyoError } = this.state;
181
- rollbar?.error(error);
182
- console.error("Error:", xyoError, errorInfo);
183
- if (rethrow) {
184
- throw error;
185
- }
186
- }
187
- render() {
188
- const { xyoError } = this.state;
189
- const { children, boundaryName, errorComponent, scope, title } = this.props;
190
- if (xyoError) {
191
- if (errorComponent) {
192
- return errorComponent(xyoError);
193
- }
194
- return /* @__PURE__ */ React5.createElement(ErrorRender, {
195
- error: xyoError,
196
- errorContext: `${boundaryName} Boundary`,
197
- scope,
198
- title
199
- });
200
- }
201
- return children;
202
- }
203
- };
204
- var ThrownErrorBoundary = /* @__PURE__ */ __name(({ rollbar, ...props }) => {
205
- const { rollbar: rollbarErrorReporter } = useErrorReporter();
125
+ // src/contexts/ErrorReporter/Provider.tsx
126
+ import { useRollbar } from "@rollbar/react";
127
+ import React5 from "react";
128
+
129
+ // src/contexts/ErrorReporter/Context.ts
130
+ import { createContext } from "react";
131
+ var ErrorReporterContext = createContext({});
132
+
133
+ // src/contexts/ErrorReporter/Provider.tsx
134
+ var ErrorReporterProvider = /* @__PURE__ */ __name(({ children, rollbar: rollbarProp }) => {
206
135
  let rollbarFromHook;
207
136
  try {
208
- rollbarFromHook = useRollbar2();
137
+ rollbarFromHook = useRollbar();
209
138
  } catch {
210
139
  }
211
- return /* @__PURE__ */ React5.createElement(ThrownErrorBoundaryInner, {
212
- rollbar: rollbar ?? rollbarErrorReporter ?? rollbarFromHook,
213
- ...props
214
- });
215
- }, "ThrownErrorBoundary");
140
+ const rollbar = rollbarProp ?? rollbarFromHook;
141
+ if (!rollbar) {
142
+ throw new Error("ErrorReporterProvider unable to find a Rollbar instance either passed as prop or from Provider");
143
+ }
144
+ return /* @__PURE__ */ React5.createElement(ErrorReporterContext.Provider, {
145
+ value: {
146
+ rollbar
147
+ }
148
+ }, children);
149
+ }, "ErrorReporterProvider");
150
+
151
+ // src/contexts/ErrorReporter/useErrorReporter.tsx
152
+ import { useContext } from "react";
153
+ var useErrorReporter = /* @__PURE__ */ __name(() => {
154
+ const context = useContext(ErrorReporterContext);
155
+ if (context === void 0) {
156
+ console.warn("useErrorReporter must be used within a ErrorReporterContext");
157
+ }
158
+ return context ?? {};
159
+ }, "useErrorReporter");
216
160
  export {
217
161
  ErrorAlert,
218
162
  ErrorBoundary,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/ErrorBoundary.tsx","../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useErrorReporter.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx"],"sourcesContent":["import { Typography } from '@mui/material'\nimport { FlexCol } from '@xylabs/react-flexbox'\nimport type { ErrorInfo, ReactNode } from 'react'\nimport React, { Component } from 'react'\n\nexport interface ErrorBoundaryProps {\n children: ReactNode\n // fallback as a static ReactNode value\n fallback?: ReactNode\n // fallback element that can receive the error as a prop\n fallbackWithError?: (error: Error) => ReactNode\n scope?: string\n}\n\nexport interface ErrorBoundaryState {\n error?: Error\n}\n\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\n constructor(props: ErrorBoundaryProps) {\n super(props)\n this.state = { error: undefined }\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error }\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n console.error(`${error}: ${errorInfo}`)\n }\n\n override render() {\n if (this.state.error) {\n if (this.props.fallbackWithError) {\n return this.props.fallbackWithError(this.state.error)\n }\n return (\n this.props.fallback ?? (\n <FlexCol>\n <Typography variant=\"h1\">Something went wrong.</Typography>\n {this.props.scope && (\n <Typography variant=\"h2\">\n [\n {this.props.scope}\n ]\n </Typography>\n )}\n <Typography variant=\"body1\">\n [\n {this.state.error?.message}\n ]\n </Typography>\n </FlexCol>\n )\n )\n }\n\n return this.props.children\n }\n}\n","import { useRollbar } from '@rollbar/react'\nimport type { ModuleError } from '@xyo-network/payload-model'\nimport { ModuleErrorSchema } from '@xyo-network/payload-model'\nimport type {\n ErrorInfo, FC, ReactNode,\n} from 'react'\nimport React, { Component } from 'react'\nimport type Rollbar from 'rollbar'\n\nimport { useErrorReporter } from '../../contexts/index.ts'\nimport { ErrorRender } from '../ErrorRender/index.ts'\n\nexport interface ThrownErrorBoundaryProps {\n boundaryName?: string\n children: ReactNode\n errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode\n rethrow?: boolean\n rollbar?: Rollbar\n scope?: string\n title?: string\n}\n\nexport interface ThrownErrorBoundaryState {\n xyoError?: ModuleError\n}\n\nclass ThrownErrorBoundaryInner extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {\n override state: ThrownErrorBoundaryState = { xyoError: undefined }\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true, xyoError: ThrownErrorBoundaryInner.normalizeError(error) } as ThrownErrorBoundaryState\n }\n\n static normalizeError(error: Error | ModuleError): ModuleError {\n return (\n (error as ModuleError).schema === ModuleErrorSchema\n ? error\n : {\n message: error.message, schema: ModuleErrorSchema, sources: [],\n }) as ModuleError\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n const { rethrow, rollbar } = this.props\n const { xyoError } = this.state\n\n rollbar?.error(error)\n\n console.error('Error:', xyoError, errorInfo)\n if (rethrow) {\n throw error\n }\n }\n\n override render() {\n const { xyoError } = this.state\n const {\n children, boundaryName, errorComponent, scope, title,\n } = this.props\n if (xyoError) {\n if (errorComponent) {\n return errorComponent(xyoError)\n }\n return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} scope={scope} title={title} />\n }\n\n return children\n }\n}\n\n// calling the hook outside of the component since only can be called in functional component\nexport const ThrownErrorBoundary: FC<ThrownErrorBoundaryProps> = ({ rollbar, ...props }) => {\n const { rollbar: rollbarErrorReporter } = useErrorReporter()\n let rollbarFromHook: Rollbar | undefined\n // safely call the hook\n try {\n rollbarFromHook = useRollbar()\n } catch {}\n return <ThrownErrorBoundaryInner rollbar={rollbar ?? rollbarErrorReporter ?? rollbarFromHook} {...props} />\n}\n","import { useRollbar } from '@rollbar/react'\nimport type { WithChildren } from '@xylabs/react-shared'\nimport React from 'react'\nimport type Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context.ts'\n\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n\nconst ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar: rollbarProp }) => {\n let rollbarFromHook: Rollbar | undefined\n // safely call the hook\n try {\n rollbarFromHook = useRollbar()\n } catch {}\n\n const rollbar = rollbarProp ?? rollbarFromHook\n\n if (!rollbar) {\n throw new Error('ErrorReporterProvider unable to find a Rollbar instance either passed as prop or from Provider')\n }\n\n // eslint-disable-next-line @eslint-react/no-unstable-context-value\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n\nexport { ErrorReporterProvider }\n","import { createContext } from 'react'\n\nimport type { ErrorReporterContextState } from './State.ts'\n\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context.ts'\n\nexport const useErrorReporter = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useErrorReporter must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport type { AlertProps } from '@mui/material'\nimport {\n Alert, AlertTitle, Typography,\n} from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport type { ModuleError } from '@xyo-network/payload-model'\nimport React from 'react'\n\nexport interface ErrorAlertProps extends AlertProps {\n error?: ModuleError | Error | string\n /** @deprecated use scope instead */\n errorContext?: string\n onCancel?: () => void\n scope?: string\n}\n\nexport const ErrorAlert: React.FC<ErrorAlertProps> = ({\n title = 'Whoops! Something went wrong',\n onCancel,\n error = 'An unknown error occurred',\n errorContext,\n scope,\n ...props\n}) => {\n const finalScope = scope ?? errorContext\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>{title}</AlertTitle>\n {finalScope\n ? (\n <div>\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Scope:\n </Typography>\n <Typography variant=\"caption\">{finalScope}</Typography>\n </div>\n )\n : null}\n <div>\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{typeof error === 'string' ? error : error?.message}</Typography>\n </div>\n {onCancel\n ? (\n <ButtonEx\n variant=\"outlined\"\n size=\"small\"\n onClick={onCancel}\n position=\"absolute\"\n style={{ right: 8, top: 8 }}\n >\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n )\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport React, { useEffect } from 'react'\n\nimport { ErrorAlert } from './ErrorAlert.tsx'\nimport type { ErrorRenderProps } from './Props.ts'\n\nexport const ErrorRender: React.FC<ErrorRenderProps> = ({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n scope,\n useLocation,\n ...props\n}) => {\n const location = useLocation?.()\n useEffect(() => {\n if (location) {\n // ensure we end up at the same place we are now after logging in\n location.state = { from: { pathname: globalThis.location.pathname } }\n }\n }, [location])\n\n useEffect(() => {\n if (error) {\n globalThis.rollbar?.error(error)\n }\n }, [error])\n\n return error\n ? (\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay\n ? customError\n : (\n <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} scope={scope} />\n </FlexCol>\n )}\n </FlexCol>\n )\n : <>{children}</>\n}\n"],"mappings":";;;;AAAA,SAASA,kBAAkB;AAC3B,SAASC,eAAe;AAExB,OAAOC,SAASC,iBAAiB;AAe1B,IAAMC,gBAAN,cAA4BC,UAAAA;EAlBnC,OAkBmCA;;;EACjCC,YAAYC,OAA2B;AACrC,UAAMA,KAAAA;AACN,SAAKC,QAAQ;MAAEC,OAAOC;IAAU;EAClC;EAEA,OAAOC,yBAAyBF,OAAc;AAC5C,WAAO;MAAEA;IAAM;EACjB;EAESG,kBAAkBH,OAAcI,WAAsB;AAC7DC,YAAQL,MAAM,GAAGA,KAAAA,KAAUI,SAAAA,EAAW;EACxC;EAESE,SAAS;AAChB,QAAI,KAAKP,MAAMC,OAAO;AACpB,UAAI,KAAKF,MAAMS,mBAAmB;AAChC,eAAO,KAAKT,MAAMS,kBAAkB,KAAKR,MAAMC,KAAK;MACtD;AACA,aACE,KAAKF,MAAMU,YACT,sBAAA,cAACC,SAAAA,MACC,sBAAA,cAACC,YAAAA;QAAWC,SAAQ;SAAK,uBAAA,GACxB,KAAKb,MAAMc,SACV,sBAAA,cAACF,YAAAA;QAAWC,SAAQ;SAAK,KAEtB,KAAKb,MAAMc,OAAM,GAAA,GAItB,sBAAA,cAACF,YAAAA;QAAWC,SAAQ;SAAQ,KAEzB,KAAKZ,MAAMC,OAAOa,SAAQ,GAAA,CAAA;IAMrC;AAEA,WAAO,KAAKf,MAAMgB;EACpB;AACF;;;AC5DA,SAASC,cAAAA,mBAAkB;AAE3B,SAASC,yBAAyB;AAIlC,OAAOC,UAASC,aAAAA,kBAAiB;;;ACNjC,SAASC,kBAAkB;AAE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OAAc;AAC5C,WAAO;MAAEC,UAAU;MAAMJ,UAAUH,0BAAyBQ,eAAeF,KAAAA;IAAO;EACpF;EAEA,OAAOE,eAAeF,OAAyC;AAC7D,WACGA,MAAsBG,WAAWC,oBAC9BJ,QACA;MACEK,SAASL,MAAMK;MAASF,QAAQC;MAAmBE,SAAS,CAAA;IAC9D;EACR;EAESC,kBAAkBP,OAAcQ,WAAsB;AAC7D,UAAM,EAAEC,SAASC,QAAO,IAAK,KAAKC;AAClC,UAAM,EAAEd,SAAQ,IAAK,KAAKD;AAE1Bc,aAASV,MAAMA,KAAAA;AAEfY,YAAQZ,MAAM,UAAUH,UAAUW,SAAAA;AAClC,QAAIC,SAAS;AACX,YAAMT;IACR;EACF;EAESa,SAAS;AAChB,UAAM,EAAEhB,SAAQ,IAAK,KAAKD;AAC1B,UAAM,EACJkB,UAAUC,cAAcC,gBAAgBC,OAAOC,MAAK,IAClD,KAAKP;AACT,QAAId,UAAU;AACZ,UAAImB,gBAAgB;AAClB,eAAOA,eAAenB,QAAAA;MACxB;AACA,aAAO,gBAAAsB,OAAA,cAACC,aAAAA;QAAYpB,OAAOH;QAAUwB,cAAc,GAAGN,YAAAA;QAAyBE;QAAcC;;IAC/F;AAEA,WAAOJ;EACT;AACF;AAGO,IAAMQ,sBAAoD,wBAAC,EAAEZ,SAAS,GAAGC,MAAAA,MAAO;AACrF,QAAM,EAAED,SAASa,qBAAoB,IAAKC,iBAAAA;AAC1C,MAAIC;AAEJ,MAAI;AACFA,sBAAkBC,YAAAA;EACpB,QAAQ;EAAC;AACT,SAAO,gBAAAP,OAAA,cAACzB,0BAAAA;IAAyBgB,SAASA,WAAWa,wBAAwBE;IAAkB,GAAGd;;AACpG,GARiE;","names":["Typography","FlexCol","React","Component","ErrorBoundary","Component","constructor","props","state","error","undefined","getDerivedStateFromError","componentDidCatch","errorInfo","console","render","fallbackWithError","fallback","FlexCol","Typography","variant","scope","message","children","useRollbar","ModuleErrorSchema","React","Component","useRollbar","React","createContext","ErrorReporterContext","ErrorReporterProvider","children","rollbar","rollbarProp","rollbarFromHook","useRollbar","Error","React","ErrorReporterContext","Provider","value","useContext","useErrorReporter","context","useContext","ErrorReporterContext","undefined","console","warn","ExitToApp","ExitIcon","Alert","AlertTitle","Typography","ButtonEx","React","ErrorAlert","title","onCancel","error","errorContext","scope","props","finalScope","React","Alert","severity","AlertTitle","div","Typography","variant","mr","fontWeight","message","ButtonEx","size","onClick","position","style","right","top","ExitIcon","fontSize","FlexCol","React","useEffect","ErrorRender","onCancel","error","noErrorDisplay","customError","children","errorContext","scope","useLocation","props","location","useEffect","state","from","pathname","globalThis","rollbar","React","FlexCol","alignItems","ErrorAlert","ThrownErrorBoundaryInner","Component","state","xyoError","undefined","getDerivedStateFromError","error","hasError","normalizeError","schema","ModuleErrorSchema","message","sources","componentDidCatch","errorInfo","rethrow","rollbar","props","console","render","children","boundaryName","errorComponent","scope","title","React","ErrorRender","errorContext","ThrownErrorBoundary","rollbarErrorReporter","useErrorReporter","rollbarFromHook","useRollbar"]}
1
+ {"version":3,"sources":["../../src/components/ErrorBoundary.tsx","../../src/components/ErrorBoundary/ThrownErrorBoundary.tsx","../../src/components/ErrorRender/ErrorAlert.tsx","../../src/components/ErrorRender/Render.tsx","../../src/contexts/ErrorReporter/Provider.tsx","../../src/contexts/ErrorReporter/Context.ts","../../src/contexts/ErrorReporter/useErrorReporter.tsx"],"sourcesContent":["import { Typography } from '@mui/material'\nimport { FlexCol } from '@xylabs/react-flexbox'\nimport type { ErrorInfo, ReactNode } from 'react'\nimport React, { Component } from 'react'\n\n/** @deprecated use from @xylabs/react-error instead */\nexport interface ErrorBoundaryProps {\n children: ReactNode\n // fallback as a static ReactNode value\n fallback?: ReactNode\n // fallback element that can receive the error as a prop\n fallbackWithError?: (error: Error) => ReactNode\n scope?: string\n}\n\n/** @deprecated use from @xylabs/react-error instead */\nexport interface ErrorBoundaryState {\n error?: Error\n}\n\n/** @deprecated use from @xylabs/react-error instead */\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\n constructor(props: ErrorBoundaryProps) {\n super(props)\n this.state = { error: undefined }\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error }\n }\n\n override componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n console.error(`${error}: ${errorInfo}`)\n }\n\n override render() {\n if (this.state.error) {\n if (this.props.fallbackWithError) {\n return this.props.fallbackWithError(this.state.error)\n }\n return (\n this.props.fallback ?? (\n <FlexCol>\n <Typography variant=\"h1\">Something went wrong.</Typography>\n {this.props.scope && (\n <Typography variant=\"h2\">\n [\n {this.props.scope}\n ]\n </Typography>\n )}\n <Typography variant=\"body1\">\n [\n {this.state.error?.message}\n ]\n </Typography>\n </FlexCol>\n )\n )\n }\n\n return this.props.children\n }\n}\n","import type { ThrownErrorBoundaryProps } from '@xylabs/react-error'\nimport { ThrownErrorBoundary as ThrownErrorBoundaryBase } from '@xylabs/react-error'\nimport type { ModuleError } from '@xyo-network/payload-model'\nimport type { FC } from 'react'\nimport React from 'react'\n\n// calling the hook outside of the component since only can be called in functional component\nexport const ThrownErrorBoundary: FC<ThrownErrorBoundaryProps<ModuleError>> = (props) => {\n return <ThrownErrorBoundaryBase<ModuleError> {...props} />\n}\n","import { ExitToApp as ExitIcon } from '@mui/icons-material'\nimport type { AlertProps } from '@mui/material'\nimport {\n Alert, AlertTitle, Typography,\n} from '@mui/material'\nimport { ButtonEx } from '@xylabs/react-button'\nimport React from 'react'\n\nexport interface ErrorAlertProps<T = void> extends AlertProps {\n error?: T | Error | string\n /** @deprecated use scope instead */\n errorContext?: string\n onCancel?: () => void\n scope?: string\n}\n\nexport function ErrorAlert<T = void>({\n title = 'Whoops! Something went wrong',\n onCancel,\n error = 'An unknown error occurred',\n errorContext,\n scope,\n ...props\n}: ErrorAlertProps<T>): JSX.Element {\n const finalScope = scope ?? errorContext\n return (\n <Alert severity=\"error\" {...props}>\n <AlertTitle>{title}</AlertTitle>\n {finalScope\n ? (\n <div>\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Scope:\n </Typography>\n <Typography variant=\"caption\">{finalScope}</Typography>\n </div>\n )\n : null}\n <div>\n <Typography variant=\"caption\" mr={0.5} fontWeight=\"bold\">\n Error:\n </Typography>\n <Typography variant=\"caption\">{typeof error === 'string' ? error : (error as Error)?.message}</Typography>\n </div>\n {onCancel\n ? (\n <ButtonEx\n variant=\"outlined\"\n size=\"small\"\n onClick={onCancel}\n position=\"absolute\"\n style={{ right: 8, top: 8 }}\n >\n <ExitIcon fontSize=\"small\" />\n </ButtonEx>\n )\n : null}\n </Alert>\n )\n}\n","import { FlexCol } from '@xylabs/react-flexbox'\nimport React, { useEffect } from 'react'\n\nimport { ErrorAlert } from './ErrorAlert.tsx'\nimport type { ErrorRenderProps } from './Props.ts'\n\nexport function ErrorRender<T = void>({\n onCancel,\n error,\n noErrorDisplay = false,\n customError = null,\n children,\n errorContext,\n scope,\n useLocation,\n ...props\n}: ErrorRenderProps<T>): JSX.Element {\n const location = useLocation?.()\n useEffect(() => {\n if (location) {\n // ensure we end up at the same place we are now after logging in\n location.state = { from: { pathname: globalThis.location.pathname } }\n }\n }, [location])\n\n useEffect(() => {\n if (error) {\n globalThis.rollbar?.error(error)\n }\n }, [error])\n\n return error\n ? (\n <FlexCol alignItems=\"stretch\" {...props}>\n {noErrorDisplay\n ? customError\n : (\n <FlexCol alignItems=\"center\" {...props}>\n <ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} scope={scope} />\n </FlexCol>\n )}\n </FlexCol>\n )\n : <>{children}</>\n}\n","import { useRollbar } from '@rollbar/react'\nimport type { PropsWithChildren } from 'react'\nimport React from 'react'\nimport type Rollbar from 'rollbar'\n\nimport { ErrorReporterContext } from './Context.ts'\n\n/** @deprecated use from @xylabs/react-error instead */\nexport interface ErrorReporterProviderProps {\n rollbar: Rollbar\n}\n/** @deprecated use from @xylabs/react-error instead */\nexport const ErrorReporterProvider: React.FC<PropsWithChildren<ErrorReporterProviderProps>> = ({ children, rollbar: rollbarProp }) => {\n let rollbarFromHook: Rollbar | undefined\n // safely call the hook\n try {\n rollbarFromHook = useRollbar()\n } catch {}\n\n const rollbar = rollbarProp ?? rollbarFromHook\n\n if (!rollbar) {\n throw new Error('ErrorReporterProvider unable to find a Rollbar instance either passed as prop or from Provider')\n }\n\n // eslint-disable-next-line @eslint-react/no-unstable-context-value\n return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>\n}\n","import { createContext } from 'react'\n\nimport type { ErrorReporterContextState } from './State.ts'\n\n/** @deprecated use from @xylabs/react-error instead */\nexport const ErrorReporterContext = createContext<ErrorReporterContextState>({})\n","import { useContext } from 'react'\n\nimport { ErrorReporterContext } from './Context.ts'\n\n/** @deprecated use from @xylabs/react-error instead */\nexport const useErrorReporter = () => {\n const context = useContext(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useErrorReporter must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n"],"mappings":";;;;AAAA,SAASA,kBAAkB;AAC3B,SAASC,eAAe;AAExB,OAAOC,SAASC,iBAAiB;AAkB1B,IAAMC,gBAAN,cAA4BC,UAAAA;EArBnC,OAqBmCA;;;EACjCC,YAAYC,OAA2B;AACrC,UAAMA,KAAAA;AACN,SAAKC,QAAQ;MAAEC,OAAOC;IAAU;EAClC;EAEA,OAAOC,yBAAyBF,OAAc;AAC5C,WAAO;MAAEA;IAAM;EACjB;EAESG,kBAAkBH,OAAcI,WAAsB;AAC7DC,YAAQL,MAAM,GAAGA,KAAAA,KAAUI,SAAAA,EAAW;EACxC;EAESE,SAAS;AAChB,QAAI,KAAKP,MAAMC,OAAO;AACpB,UAAI,KAAKF,MAAMS,mBAAmB;AAChC,eAAO,KAAKT,MAAMS,kBAAkB,KAAKR,MAAMC,KAAK;MACtD;AACA,aACE,KAAKF,MAAMU,YACT,sBAAA,cAACC,SAAAA,MACC,sBAAA,cAACC,YAAAA;QAAWC,SAAQ;SAAK,uBAAA,GACxB,K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AAC,OAAA,cAACC,qBAAqBC,UAAQ;IAACC,OAAO;MAAER;IAAQ;KAAID,QAAAA;AAC7D,GAf8F;;;AEZ9F,SAASU,kBAAkB;AAKpB,IAAMC,mBAAmB,6BAAA;AAC9B,QAAMC,UAAUC,WAAWC,oBAAAA;AAC3B,MAAIF,YAAYG,QAAW;AACzBC,YAAQC,KAAK,6DAAA;EACf;AAEA,SAAOL,WAAW,CAAC;AACrB,GAPgC;","names":["Typography","FlexCol","React","Component","ErrorBoundary","Component","constructor","props","state","error","undefined","getDerivedStateFromError","componentDidCatch","errorInfo","console","render","fallbackWithError","fallback","FlexCol","Typography","variant","scope","message","children","ThrownErrorBoundary","ThrownErrorBoundaryBase","React","ThrownErrorBoundary","props","React","ThrownErrorBoundaryBase","ExitToApp","ExitIcon","Alert","AlertTitle","Typography","ButtonEx","React","ErrorAlert","title","onCancel","error","errorContext","scope","props","finalScope","React","Alert","severity","AlertTitle","div","Typography","variant","mr","fontWeight","message","ButtonEx","size","onClick","position","style","right","top","ExitIcon","fontSize","FlexCol","React","useEffect","ErrorRender","onCancel","error","noErrorDisplay","customError","children","errorContext","scope","useLocation","props","location","useEffect","state","from","pathname","globalThis","rollbar","React","FlexCol","alignItems","ErrorAlert","useRollbar","React","createContext","ErrorReporterContext","ErrorReporterProvider","children","rollbar","rollbarProp","rollbarFromHook","useRollbar","Error","React","ErrorReporterContext","Provider","value","useContext","useErrorReporter","context","useContext","ErrorReporterContext","undefined","console","warn"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/react-error",
3
- "version": "4.1.8",
3
+ "version": "4.1.10",
4
4
  "description": "Common React library for all XYO projects that use React",
5
5
  "keywords": [
6
6
  "xyo",
@@ -44,10 +44,10 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@rollbar/react": "^0.12.0-beta",
47
- "@xylabs/react-button": "^5.2.4",
48
- "@xylabs/react-flexbox": "^5.2.4",
49
- "@xylabs/react-shared": "^5.2.4",
50
- "@xyo-network/payload-model": "^3.3.1",
47
+ "@xylabs/react-button": "^5.2.9",
48
+ "@xylabs/react-error": "^5.2.9",
49
+ "@xylabs/react-flexbox": "^5.2.9",
50
+ "@xyo-network/payload-model": "^3.3.2",
51
51
  "prop-types": "^15.8.1",
52
52
  "react-router-dom": "^6.27.0"
53
53
  },
@@ -1,80 +1,10 @@
1
- import { useRollbar } from '@rollbar/react'
1
+ import type { ThrownErrorBoundaryProps } from '@xylabs/react-error'
2
+ import { ThrownErrorBoundary as ThrownErrorBoundaryBase } from '@xylabs/react-error'
2
3
  import type { ModuleError } from '@xyo-network/payload-model'
3
- import { ModuleErrorSchema } from '@xyo-network/payload-model'
4
- import type {
5
- ErrorInfo, FC, ReactNode,
6
- } from 'react'
7
- import React, { Component } from 'react'
8
- import type Rollbar from 'rollbar'
9
-
10
- import { useErrorReporter } from '../../contexts/index.ts'
11
- import { ErrorRender } from '../ErrorRender/index.ts'
12
-
13
- export interface ThrownErrorBoundaryProps {
14
- boundaryName?: string
15
- children: ReactNode
16
- errorComponent?: (e: ModuleError, boundaryName?: string) => ReactNode
17
- rethrow?: boolean
18
- rollbar?: Rollbar
19
- scope?: string
20
- title?: string
21
- }
22
-
23
- export interface ThrownErrorBoundaryState {
24
- xyoError?: ModuleError
25
- }
26
-
27
- class ThrownErrorBoundaryInner extends Component<ThrownErrorBoundaryProps, ThrownErrorBoundaryState> {
28
- override state: ThrownErrorBoundaryState = { xyoError: undefined }
29
-
30
- static getDerivedStateFromError(error: Error) {
31
- return { hasError: true, xyoError: ThrownErrorBoundaryInner.normalizeError(error) } as ThrownErrorBoundaryState
32
- }
33
-
34
- static normalizeError(error: Error | ModuleError): ModuleError {
35
- return (
36
- (error as ModuleError).schema === ModuleErrorSchema
37
- ? error
38
- : {
39
- message: error.message, schema: ModuleErrorSchema, sources: [],
40
- }) as ModuleError
41
- }
42
-
43
- override componentDidCatch(error: Error, errorInfo: ErrorInfo) {
44
- const { rethrow, rollbar } = this.props
45
- const { xyoError } = this.state
46
-
47
- rollbar?.error(error)
48
-
49
- console.error('Error:', xyoError, errorInfo)
50
- if (rethrow) {
51
- throw error
52
- }
53
- }
54
-
55
- override render() {
56
- const { xyoError } = this.state
57
- const {
58
- children, boundaryName, errorComponent, scope, title,
59
- } = this.props
60
- if (xyoError) {
61
- if (errorComponent) {
62
- return errorComponent(xyoError)
63
- }
64
- return <ErrorRender error={xyoError} errorContext={`${boundaryName} Boundary`} scope={scope} title={title} />
65
- }
66
-
67
- return children
68
- }
69
- }
4
+ import type { FC } from 'react'
5
+ import React from 'react'
70
6
 
71
7
  // calling the hook outside of the component since only can be called in functional component
72
- export const ThrownErrorBoundary: FC<ThrownErrorBoundaryProps> = ({ rollbar, ...props }) => {
73
- const { rollbar: rollbarErrorReporter } = useErrorReporter()
74
- let rollbarFromHook: Rollbar | undefined
75
- // safely call the hook
76
- try {
77
- rollbarFromHook = useRollbar()
78
- } catch {}
79
- return <ThrownErrorBoundaryInner rollbar={rollbar ?? rollbarErrorReporter ?? rollbarFromHook} {...props} />
8
+ export const ThrownErrorBoundary: FC<ThrownErrorBoundaryProps<ModuleError>> = (props) => {
9
+ return <ThrownErrorBoundaryBase<ModuleError> {...props} />
80
10
  }
@@ -0,0 +1,77 @@
1
+ import { useRollbar } from '@rollbar/react'
2
+ import type { ErrorInfo, ReactNode } from 'react'
3
+ import React, { Component } from 'react'
4
+ import type Rollbar from 'rollbar'
5
+
6
+ import { useErrorReporter } from '../../contexts/index.ts'
7
+ import { ErrorRender } from '../ErrorRender/index.ts'
8
+
9
+ /** @deprecated use from @xylabs/react-error instead */
10
+ export type ErrorEx<T = void> = T extends void ? Error : T | Error
11
+
12
+ /** @deprecated use from @xylabs/react-error instead */
13
+ export interface ThrownErrorBoundaryProps<T = void> {
14
+ boundaryName?: string
15
+ children: ReactNode
16
+ errorComponent?: (e: ErrorEx<T>, boundaryName?: string) => ReactNode
17
+ rethrow?: boolean
18
+ rollbar?: Rollbar
19
+ scope?: string
20
+ title?: string
21
+ }
22
+
23
+ /** @deprecated use from @xylabs/react-error instead */
24
+ export interface ThrownErrorBoundaryState<T = void> {
25
+ errorEx?: ErrorEx<T>
26
+ }
27
+
28
+ class ThrownErrorBoundaryInner<T> extends Component<ThrownErrorBoundaryProps<T>, ThrownErrorBoundaryState<T>> {
29
+ override state: ThrownErrorBoundaryState<T> = { errorEx: undefined }
30
+
31
+ static getDerivedStateFromError<T = void>(error: ErrorEx<T>) {
32
+ return { hasError: true, xyoError: this.normalizeError<T>(error) } as ThrownErrorBoundaryState<T>
33
+ }
34
+
35
+ static normalizeError<T>(_error: ErrorEx<T>): T {
36
+ throw new Error('Method not implemented.')
37
+ }
38
+
39
+ override componentDidCatch(error: Error, errorInfo: ErrorInfo) {
40
+ const { rethrow, rollbar } = this.props
41
+ const { errorEx } = this.state
42
+
43
+ rollbar?.error(error)
44
+
45
+ console.error('Error:', errorEx, errorInfo)
46
+ if (rethrow) {
47
+ throw error
48
+ }
49
+ }
50
+
51
+ override render() {
52
+ const { errorEx } = this.state
53
+ const {
54
+ children, boundaryName, errorComponent, scope, title,
55
+ } = this.props
56
+ if (errorEx) {
57
+ if (errorComponent) {
58
+ return errorComponent(errorEx)
59
+ }
60
+ return <ErrorRender<T> error={errorEx} errorContext={`${boundaryName} Boundary`} scope={scope} title={title} />
61
+ }
62
+
63
+ return children
64
+ }
65
+ }
66
+
67
+ // calling the hook outside of the component since only can be called in functional component
68
+ /** @deprecated use from @xylabs/react-error instead */
69
+ export function ThrownErrorBoundaryBase<T = void>({ rollbar, ...props }: ThrownErrorBoundaryProps<T>): JSX.Element {
70
+ const { rollbar: rollbarErrorReporter } = useErrorReporter()
71
+ let rollbarFromHook: Rollbar | undefined
72
+ // safely call the hook
73
+ try {
74
+ rollbarFromHook = useRollbar()
75
+ } catch {}
76
+ return <ThrownErrorBoundaryInner<T> rollbar={rollbar ?? rollbarErrorReporter ?? rollbarFromHook} {...props} />
77
+ }
@@ -3,6 +3,7 @@ import { FlexCol } from '@xylabs/react-flexbox'
3
3
  import type { ErrorInfo, ReactNode } from 'react'
4
4
  import React, { Component } from 'react'
5
5
 
6
+ /** @deprecated use from @xylabs/react-error instead */
6
7
  export interface ErrorBoundaryProps {
7
8
  children: ReactNode
8
9
  // fallback as a static ReactNode value
@@ -12,10 +13,12 @@ export interface ErrorBoundaryProps {
12
13
  scope?: string
13
14
  }
14
15
 
16
+ /** @deprecated use from @xylabs/react-error instead */
15
17
  export interface ErrorBoundaryState {
16
18
  error?: Error
17
19
  }
18
20
 
21
+ /** @deprecated use from @xylabs/react-error instead */
19
22
  export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
20
23
  constructor(props: ErrorBoundaryProps) {
21
24
  super(props)
@@ -4,25 +4,24 @@ import {
4
4
  Alert, AlertTitle, Typography,
5
5
  } from '@mui/material'
6
6
  import { ButtonEx } from '@xylabs/react-button'
7
- import type { ModuleError } from '@xyo-network/payload-model'
8
7
  import React from 'react'
9
8
 
10
- export interface ErrorAlertProps extends AlertProps {
11
- error?: ModuleError | Error | string
9
+ export interface ErrorAlertProps<T = void> extends AlertProps {
10
+ error?: T | Error | string
12
11
  /** @deprecated use scope instead */
13
12
  errorContext?: string
14
13
  onCancel?: () => void
15
14
  scope?: string
16
15
  }
17
16
 
18
- export const ErrorAlert: React.FC<ErrorAlertProps> = ({
17
+ export function ErrorAlert<T = void>({
19
18
  title = 'Whoops! Something went wrong',
20
19
  onCancel,
21
20
  error = 'An unknown error occurred',
22
21
  errorContext,
23
22
  scope,
24
23
  ...props
25
- }) => {
24
+ }: ErrorAlertProps<T>): JSX.Element {
26
25
  const finalScope = scope ?? errorContext
27
26
  return (
28
27
  <Alert severity="error" {...props}>
@@ -41,7 +40,7 @@ export const ErrorAlert: React.FC<ErrorAlertProps> = ({
41
40
  <Typography variant="caption" mr={0.5} fontWeight="bold">
42
41
  Error:
43
42
  </Typography>
44
- <Typography variant="caption">{typeof error === 'string' ? error : error?.message}</Typography>
43
+ <Typography variant="caption">{typeof error === 'string' ? error : (error as Error)?.message}</Typography>
45
44
  </div>
46
45
  {onCancel
47
46
  ? (
@@ -1,11 +1,12 @@
1
1
  import type { FlexBoxProps } from '@xylabs/react-flexbox'
2
- import type { ModuleError } from '@xyo-network/payload-model'
3
2
  import type { ReactNode } from 'react'
4
3
  import type { Location } from 'react-router-dom'
5
4
 
6
- export interface ErrorRenderProps extends FlexBoxProps {
5
+ export type ErrorEx<T = void> = T extends void ? Error : T | Error
6
+
7
+ export interface ErrorRenderProps<T = void> extends FlexBoxProps {
7
8
  customError?: ReactNode
8
- error?: ModuleError | Error
9
+ error?: ErrorEx<T>
9
10
  errorContext?: string
10
11
  noErrorDisplay?: boolean
11
12
  noReAuth?: boolean
@@ -4,7 +4,7 @@ import React, { useEffect } from 'react'
4
4
  import { ErrorAlert } from './ErrorAlert.tsx'
5
5
  import type { ErrorRenderProps } from './Props.ts'
6
6
 
7
- export const ErrorRender: React.FC<ErrorRenderProps> = ({
7
+ export function ErrorRender<T = void>({
8
8
  onCancel,
9
9
  error,
10
10
  noErrorDisplay = false,
@@ -14,7 +14,7 @@ export const ErrorRender: React.FC<ErrorRenderProps> = ({
14
14
  scope,
15
15
  useLocation,
16
16
  ...props
17
- }) => {
17
+ }: ErrorRenderProps<T>): JSX.Element {
18
18
  const location = useLocation?.()
19
19
  useEffect(() => {
20
20
  if (location) {
@@ -2,4 +2,5 @@ import { createContext } from 'react'
2
2
 
3
3
  import type { ErrorReporterContextState } from './State.ts'
4
4
 
5
+ /** @deprecated use from @xylabs/react-error instead */
5
6
  export const ErrorReporterContext = createContext<ErrorReporterContextState>({})
@@ -1,15 +1,16 @@
1
1
  import { useRollbar } from '@rollbar/react'
2
- import type { WithChildren } from '@xylabs/react-shared'
2
+ import type { PropsWithChildren } from 'react'
3
3
  import React from 'react'
4
4
  import type Rollbar from 'rollbar'
5
5
 
6
6
  import { ErrorReporterContext } from './Context.ts'
7
7
 
8
+ /** @deprecated use from @xylabs/react-error instead */
8
9
  export interface ErrorReporterProviderProps {
9
10
  rollbar: Rollbar
10
11
  }
11
-
12
- const ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>> = ({ children, rollbar: rollbarProp }) => {
12
+ /** @deprecated use from @xylabs/react-error instead */
13
+ export const ErrorReporterProvider: React.FC<PropsWithChildren<ErrorReporterProviderProps>> = ({ children, rollbar: rollbarProp }) => {
13
14
  let rollbarFromHook: Rollbar | undefined
14
15
  // safely call the hook
15
16
  try {
@@ -25,5 +26,3 @@ const ErrorReporterProvider: React.FC<WithChildren<ErrorReporterProviderProps>>
25
26
  // eslint-disable-next-line @eslint-react/no-unstable-context-value
26
27
  return <ErrorReporterContext.Provider value={{ rollbar }}>{children}</ErrorReporterContext.Provider>
27
28
  }
28
-
29
- export { ErrorReporterProvider }
@@ -1,5 +1,6 @@
1
1
  import type Rollbar from 'rollbar'
2
2
 
3
+ /** @deprecated use from @xylabs/react-error instead */
3
4
  export interface ErrorReporterContextState {
4
5
  rollbar?: Rollbar
5
6
  }
@@ -2,6 +2,7 @@ import { useContext } from 'react'
2
2
 
3
3
  import { ErrorReporterContext } from './Context.ts'
4
4
 
5
+ /** @deprecated use from @xylabs/react-error instead */
5
6
  export const useErrorReporter = () => {
6
7
  const context = useContext(ErrorReporterContext)
7
8
  if (context === undefined) {