@xyo-network/react-error 3.0.10 → 3.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ import type { ErrorInfo, ReactNode } from 'react';
2
+ import { Component } from 'react';
3
+ export interface ErrorBoundaryProps {
4
+ children: ReactNode;
5
+ fallback?: ReactNode;
6
+ fallbackWithError?: (error: Error) => ReactNode;
7
+ scope?: string;
8
+ }
9
+ export interface ErrorBoundaryState {
10
+ error?: Error;
11
+ }
12
+ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
13
+ constructor(props: ErrorBoundaryProps);
14
+ static getDerivedStateFromError(error: Error): {
15
+ error: Error;
16
+ };
17
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
18
+ render(): string | number | boolean | Iterable<ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
19
+ }
20
+ //# sourceMappingURL=ErrorBoundary.d.ts.map
@@ -0,0 +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,3 +1,4 @@
1
+ export * from './ErrorBoundary.tsx';
1
2
  export * from './ErrorBoundary/index.ts';
2
3
  export * from './ErrorRender/index.ts';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA"}
@@ -1,14 +1,53 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
+ // src/components/ErrorBoundary.tsx
5
+ import { Typography } from "@mui/material";
6
+ import { FlexCol } from "@xylabs/react-flexbox";
7
+ import React, { Component } from "react";
8
+ var ErrorBoundary = class extends Component {
9
+ static {
10
+ __name(this, "ErrorBoundary");
11
+ }
12
+ constructor(props) {
13
+ super(props);
14
+ this.state = {
15
+ error: void 0
16
+ };
17
+ }
18
+ static getDerivedStateFromError(error) {
19
+ return {
20
+ error
21
+ };
22
+ }
23
+ componentDidCatch(error, errorInfo) {
24
+ console.error(`${error}: ${errorInfo}`);
25
+ }
26
+ render() {
27
+ if (this.state.error) {
28
+ if (this.props.fallbackWithError) {
29
+ return this.props.fallbackWithError(this.state.error);
30
+ }
31
+ return this.props.fallback ?? /* @__PURE__ */ React.createElement(FlexCol, null, /* @__PURE__ */ React.createElement(Typography, {
32
+ variant: "h1"
33
+ }, "Something went wrong."), this.props.scope && /* @__PURE__ */ React.createElement(Typography, {
34
+ variant: "h2"
35
+ }, "[", this.props.scope, "]"), /* @__PURE__ */ React.createElement(Typography, {
36
+ variant: "body1"
37
+ }, "[", this.state.error?.message, "]"));
38
+ }
39
+ return this.props.children;
40
+ }
41
+ };
42
+
4
43
  // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
5
44
  import { useRollbar as useRollbar2 } from "@rollbar/react";
6
45
  import { ModuleErrorSchema } from "@xyo-network/payload-model";
7
- import React4, { Component } from "react";
46
+ import React5, { Component as Component2 } from "react";
8
47
 
9
48
  // src/contexts/ErrorReporter/Provider.tsx
10
49
  import { useRollbar } from "@rollbar/react";
11
- import React from "react";
50
+ import React2 from "react";
12
51
 
13
52
  // src/contexts/ErrorReporter/Context.ts
14
53
  import { createContext } from "react";
@@ -25,7 +64,7 @@ var ErrorReporterProvider = /* @__PURE__ */ __name(({ children, rollbar: rollbar
25
64
  if (!rollbar) {
26
65
  throw new Error("ErrorReporterProvider unable to find a Rollbar instance either passed as prop or from Provider");
27
66
  }
28
- return /* @__PURE__ */ React.createElement(ErrorReporterContext.Provider, {
67
+ return /* @__PURE__ */ React2.createElement(ErrorReporterContext.Provider, {
29
68
  value: {
30
69
  rollbar
31
70
  }
@@ -44,27 +83,27 @@ var useErrorReporter = /* @__PURE__ */ __name(() => {
44
83
 
45
84
  // src/components/ErrorRender/ErrorAlert.tsx
46
85
  import { ExitToApp as ExitIcon } from "@mui/icons-material";
47
- import { Alert, AlertTitle, Typography } from "@mui/material";
86
+ import { Alert, AlertTitle, Typography as Typography2 } from "@mui/material";
48
87
  import { ButtonEx } from "@xylabs/react-button";
49
- import React2 from "react";
88
+ import React3 from "react";
50
89
  var ErrorAlert = /* @__PURE__ */ __name(({ title = "Whoops! Something went wrong", onCancel, error = "An unknown error occurred", errorContext, scope, ...props }) => {
51
90
  const finalScope = scope ?? errorContext;
52
- return /* @__PURE__ */ React2.createElement(Alert, {
91
+ return /* @__PURE__ */ React3.createElement(Alert, {
53
92
  severity: "error",
54
93
  ...props
55
- }, /* @__PURE__ */ React2.createElement(AlertTitle, null, title), finalScope ? /* @__PURE__ */ React2.createElement("div", null, /* @__PURE__ */ React2.createElement(Typography, {
94
+ }, /* @__PURE__ */ React3.createElement(AlertTitle, null, title), finalScope ? /* @__PURE__ */ React3.createElement("div", null, /* @__PURE__ */ React3.createElement(Typography2, {
56
95
  variant: "caption",
57
96
  mr: 0.5,
58
97
  fontWeight: "bold"
59
- }, "Scope:"), /* @__PURE__ */ React2.createElement(Typography, {
98
+ }, "Scope:"), /* @__PURE__ */ React3.createElement(Typography2, {
60
99
  variant: "caption"
61
- }, finalScope)) : null, /* @__PURE__ */ React2.createElement("div", null, /* @__PURE__ */ React2.createElement(Typography, {
100
+ }, finalScope)) : null, /* @__PURE__ */ React3.createElement("div", null, /* @__PURE__ */ React3.createElement(Typography2, {
62
101
  variant: "caption",
63
102
  mr: 0.5,
64
103
  fontWeight: "bold"
65
- }, "Error:"), /* @__PURE__ */ React2.createElement(Typography, {
104
+ }, "Error:"), /* @__PURE__ */ React3.createElement(Typography2, {
66
105
  variant: "caption"
67
- }, typeof error === "string" ? error : error?.message)), onCancel ? /* @__PURE__ */ React2.createElement(ButtonEx, {
106
+ }, typeof error === "string" ? error : error?.message)), onCancel ? /* @__PURE__ */ React3.createElement(ButtonEx, {
68
107
  variant: "outlined",
69
108
  size: "small",
70
109
  onClick: onCancel,
@@ -73,14 +112,14 @@ var ErrorAlert = /* @__PURE__ */ __name(({ title = "Whoops! Something went wrong
73
112
  right: 8,
74
113
  top: 8
75
114
  }
76
- }, /* @__PURE__ */ React2.createElement(ExitIcon, {
115
+ }, /* @__PURE__ */ React3.createElement(ExitIcon, {
77
116
  fontSize: "small"
78
117
  })) : null);
79
118
  }, "ErrorAlert");
80
119
 
81
120
  // src/components/ErrorRender/Render.tsx
82
- import { FlexCol } from "@xylabs/react-flexbox";
83
- import React3, { useEffect } from "react";
121
+ import { FlexCol as FlexCol2 } from "@xylabs/react-flexbox";
122
+ import React4, { useEffect } from "react";
84
123
  var ErrorRender = /* @__PURE__ */ __name(({ onCancel, error, noErrorDisplay = false, customError = null, children, errorContext, scope, useLocation, ...props }) => {
85
124
  const location = useLocation?.();
86
125
  useEffect(() => {
@@ -94,22 +133,22 @@ var ErrorRender = /* @__PURE__ */ __name(({ onCancel, error, noErrorDisplay = fa
94
133
  }, [
95
134
  location
96
135
  ]);
97
- return error ? /* @__PURE__ */ React3.createElement(FlexCol, {
136
+ return error ? /* @__PURE__ */ React4.createElement(FlexCol2, {
98
137
  alignItems: "stretch",
99
138
  ...props
100
- }, noErrorDisplay ? customError : /* @__PURE__ */ React3.createElement(FlexCol, {
139
+ }, noErrorDisplay ? customError : /* @__PURE__ */ React4.createElement(FlexCol2, {
101
140
  alignItems: "center",
102
141
  ...props
103
- }, /* @__PURE__ */ React3.createElement(ErrorAlert, {
142
+ }, /* @__PURE__ */ React4.createElement(ErrorAlert, {
104
143
  error,
105
144
  errorContext,
106
145
  onCancel,
107
146
  scope
108
- }))) : /* @__PURE__ */ React3.createElement(React3.Fragment, null, children) ?? null;
147
+ }))) : /* @__PURE__ */ React4.createElement(React4.Fragment, null, children) ?? null;
109
148
  }, "ErrorRender");
110
149
 
111
150
  // src/components/ErrorBoundary/ThrownErrorBoundary.tsx
112
- var ThrownErrorBoundaryInner = class ThrownErrorBoundaryInner2 extends Component {
151
+ var ThrownErrorBoundaryInner = class ThrownErrorBoundaryInner2 extends Component2 {
113
152
  static {
114
153
  __name(this, "ThrownErrorBoundaryInner");
115
154
  }
@@ -145,7 +184,7 @@ var ThrownErrorBoundaryInner = class ThrownErrorBoundaryInner2 extends Component
145
184
  if (errorComponent) {
146
185
  return errorComponent(xyoError);
147
186
  }
148
- return /* @__PURE__ */ React4.createElement(ErrorRender, {
187
+ return /* @__PURE__ */ React5.createElement(ErrorRender, {
149
188
  error: xyoError,
150
189
  errorContext: `${boundaryName} Boundary`,
151
190
  scope,
@@ -162,13 +201,14 @@ var ThrownErrorBoundary = /* @__PURE__ */ __name(({ rollbar, ...props }) => {
162
201
  rollbarFromHook = useRollbar2();
163
202
  } catch {
164
203
  }
165
- return /* @__PURE__ */ React4.createElement(ThrownErrorBoundaryInner, {
204
+ return /* @__PURE__ */ React5.createElement(ThrownErrorBoundaryInner, {
166
205
  rollbar: rollbar ?? rollbarErrorReporter ?? rollbarFromHook,
167
206
  ...props
168
207
  });
169
208
  }, "ThrownErrorBoundary");
170
209
  export {
171
210
  ErrorAlert,
211
+ ErrorBoundary,
172
212
  ErrorRender,
173
213
  ErrorReporterProvider,
174
214
  ThrownErrorBoundary,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../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 { 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: window.location.pathname } }\n }\n }, [location])\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}</> ?? null)\n}\n"],"mappings":";;;;AAAA,SAASA,cAAAA,mBAAkB;AAE3B,SAASC,yBAAyB;AAIlC,OAAOC,UAASC,iBAAiB;;;ACNjC,SAASC,kBAAkB;AAE3B,OAAOC,WAAW;;;ACFlB,SAASC,qBAAqB;AAIvB,IAAMC,uBAAuBD,cAAyC,CAAC,CAAA;;;ADO9E,IAAME,wBAA4E,wBAAC,EAAEC,UAAUC,SAASC,YAAW,MAAE;AACnH,MAAIC;AAEJ,MAAI;AACFA,sBAAkBC,WAAAA;EACpB,QAAQ;EAAC;AAET,QAAMH,UAAUC,eAAeC;AAE/B,MAAI,CAACF,SAAS;AACZ,UAAM,IAAII,MAAM,gGAAA;EAClB;AAGA,SAAO,sBAAA,cAACC,qBAAqBC,UAAQ;IAACC,OAAO;MAAEP;IAAQ;KAAID,QAAAA;AAC7D,GAfkF;;;AEXlF,SAASS,kBAAkB;AAIpB,IAAMC,mBAAmB,6BAAA;AAC9B,QAAMC,UAAUC,WAAWC,oBAAAA;AAC3B,MAAIF,YAAYG,QAAW;AACzBC,YAAQC,KAAK,6DAAA;EACf;AAEA,SAAOL,WAAW,CAAC;AACrB,GAPgC;;;ACJhC,SAASM,aAAaC,gBAAgB;AAEtC,SACEC,OAAOC,YAAYC,kBACd;AACP,SAASC,gBAAgB;AAEzB,OAAOC,YAAW;AAUX,IAAMC,aAAwC,wBAAC,EACpDC,QAAQ,gCACRC,UACAC,QAAQ,6BACRC,cACAC,OACA,GAAGC,MAAAA,MACJ;AACC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AI;AACFA,sBAAkBC,YAAAA;EACpB,QAAQ;EAAC;AACT,SAAO,gBAAAP,OAAA,cAACzB,0BAAAA;IAAyBgB,SAASA,WAAWa,wBAAwBE;IAAkB,GAAGd;;AACpG,GARiE;","names":["useRollbar","ModuleErrorSchema","React","Component","useRollbar","React","createContext","ErrorReporterContext","ErrorReporterProvider","children","rollbar","rollbarProp","rollbarFromHook","useRollbar","Error","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","window","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/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: window.location.pathname } }\n }\n }, [location])\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}</> ?? null)\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;AA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5BC,QAAkC;IAAEC,UAAUC;EAAU;EAEjE,OAAOC,yBAAyBC,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","window","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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/react-error",
3
- "version": "3.0.10",
3
+ "version": "3.0.11",
4
4
  "description": "Common React library for all XYO projects that use React",
5
5
  "keywords": [
6
6
  "xyo",
@@ -0,0 +1,61 @@
1
+ import { Typography } from '@mui/material'
2
+ import { FlexCol } from '@xylabs/react-flexbox'
3
+ import type { ErrorInfo, ReactNode } from 'react'
4
+ import React, { Component } from 'react'
5
+
6
+ export interface ErrorBoundaryProps {
7
+ children: ReactNode
8
+ // fallback as a static ReactNode value
9
+ fallback?: ReactNode
10
+ // fallback element that can receive the error as a prop
11
+ fallbackWithError?: (error: Error) => ReactNode
12
+ scope?: string
13
+ }
14
+
15
+ export interface ErrorBoundaryState {
16
+ error?: Error
17
+ }
18
+
19
+ export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
20
+ constructor(props: ErrorBoundaryProps) {
21
+ super(props)
22
+ this.state = { error: undefined }
23
+ }
24
+
25
+ static getDerivedStateFromError(error: Error) {
26
+ return { error }
27
+ }
28
+
29
+ override componentDidCatch(error: Error, errorInfo: ErrorInfo) {
30
+ console.error(`${error}: ${errorInfo}`)
31
+ }
32
+
33
+ override render() {
34
+ if (this.state.error) {
35
+ if (this.props.fallbackWithError) {
36
+ return this.props.fallbackWithError(this.state.error)
37
+ }
38
+ return (
39
+ this.props.fallback ?? (
40
+ <FlexCol>
41
+ <Typography variant="h1">Something went wrong.</Typography>
42
+ {this.props.scope && (
43
+ <Typography variant="h2">
44
+ [
45
+ {this.props.scope}
46
+ ]
47
+ </Typography>
48
+ )}
49
+ <Typography variant="body1">
50
+ [
51
+ {this.state.error?.message}
52
+ ]
53
+ </Typography>
54
+ </FlexCol>
55
+ )
56
+ )
57
+ }
58
+
59
+ return this.props.children
60
+ }
61
+ }
@@ -1,2 +1,3 @@
1
+ export * from './ErrorBoundary.tsx'
1
2
  export * from './ErrorBoundary/index.ts'
2
3
  export * from './ErrorRender/index.ts'