@xyo-network/react-error 7.5.8 → 7.5.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/components/ErrorRender/Render.d.ts.map +1 -1
- package/dist/browser/contexts/ErrorReporter/Provider.d.ts.map +1 -1
- package/dist/browser/index.mjs +82 -91
- package/dist/browser/index.mjs.map +1 -1
- package/package.json +72 -34
- package/src/components/ErrorBoundary/ThrownErrorBoundary.stories.tsx +0 -51
- package/src/components/ErrorBoundary/ThrownErrorBoundary.tsx +0 -9
- package/src/components/ErrorBoundary/ThrownErrorBoundaryBase.tsx +0 -78
- package/src/components/ErrorBoundary/index.ts +0 -1
- package/src/components/ErrorBoundary.tsx +0 -64
- package/src/components/ErrorRender/ErrorAlert.stories.tsx +0 -41
- package/src/components/ErrorRender/ErrorAlert.tsx +0 -60
- package/src/components/ErrorRender/Props.ts +0 -16
- package/src/components/ErrorRender/Render.tsx +0 -45
- package/src/components/ErrorRender/index.ts +0 -3
- package/src/components/index.ts +0 -3
- package/src/contexts/ErrorReporter/Context.ts +0 -6
- package/src/contexts/ErrorReporter/Provider.stories.tsx +0 -43
- package/src/contexts/ErrorReporter/Provider.tsx +0 -28
- package/src/contexts/ErrorReporter/State.ts +0 -6
- package/src/contexts/ErrorReporter/index.ts +0 -3
- package/src/contexts/ErrorReporter/useErrorReporter.tsx +0 -13
- package/src/contexts/index.ts +0 -1
- package/src/global.d.ts +0 -5
- package/src/index.ts +0 -2
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,2CA6BrB"}
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,KAAkB,MAAM,OAAO,CAAA;AACtC,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,CAiBzF,CAAA"}
|
package/dist/browser/index.mjs
CHANGED
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/components/ErrorBoundary.tsx
|
|
5
2
|
import { Typography } from "@mui/material";
|
|
6
3
|
import { FlexCol } from "@xylabs/react-flexbox";
|
|
7
|
-
import
|
|
4
|
+
import { Component } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
6
|
var ErrorBoundary = class extends Component {
|
|
9
|
-
static {
|
|
10
|
-
__name(this, "ErrorBoundary");
|
|
11
|
-
}
|
|
12
7
|
constructor(props) {
|
|
13
8
|
super(props);
|
|
14
|
-
this.state = {
|
|
15
|
-
error: void 0
|
|
16
|
-
};
|
|
9
|
+
this.state = { error: void 0 };
|
|
17
10
|
}
|
|
18
11
|
static getDerivedStateFromError(error) {
|
|
19
|
-
return {
|
|
20
|
-
error
|
|
21
|
-
};
|
|
12
|
+
return { error };
|
|
22
13
|
}
|
|
23
14
|
componentDidCatch(error, errorInfo) {
|
|
24
15
|
console.error(`${error}: ${errorInfo}`);
|
|
@@ -28,13 +19,19 @@ var ErrorBoundary = class extends Component {
|
|
|
28
19
|
if (this.props.fallbackWithError) {
|
|
29
20
|
return this.props.fallbackWithError(this.state.error);
|
|
30
21
|
}
|
|
31
|
-
return this.props.fallback ?? /* @__PURE__ */
|
|
32
|
-
variant: "h1"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
return this.props.fallback ?? /* @__PURE__ */ jsxs(FlexCol, { children: [
|
|
23
|
+
/* @__PURE__ */ jsx(Typography, { variant: "h1", children: "Something went wrong." }),
|
|
24
|
+
this.props.scope && /* @__PURE__ */ jsxs(Typography, { variant: "h2", children: [
|
|
25
|
+
"[",
|
|
26
|
+
this.props.scope,
|
|
27
|
+
"]"
|
|
28
|
+
] }),
|
|
29
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "body1", children: [
|
|
30
|
+
"[",
|
|
31
|
+
this.state.error?.message,
|
|
32
|
+
"]"
|
|
33
|
+
] })
|
|
34
|
+
] });
|
|
38
35
|
}
|
|
39
36
|
return this.props.children;
|
|
40
37
|
}
|
|
@@ -42,96 +39,93 @@ var ErrorBoundary = class extends Component {
|
|
|
42
39
|
|
|
43
40
|
// src/components/ErrorBoundary/ThrownErrorBoundary.tsx
|
|
44
41
|
import { ThrownErrorBoundary as ThrownErrorBoundaryBase } from "@xylabs/react-error";
|
|
45
|
-
import
|
|
46
|
-
var ThrownErrorBoundary =
|
|
47
|
-
return /* @__PURE__ */
|
|
48
|
-
}
|
|
42
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
43
|
+
var ThrownErrorBoundary = (props) => {
|
|
44
|
+
return /* @__PURE__ */ jsx2(ThrownErrorBoundaryBase, { ...props });
|
|
45
|
+
};
|
|
49
46
|
|
|
50
47
|
// src/components/ErrorRender/ErrorAlert.tsx
|
|
51
48
|
import { ExitToApp as ExitIcon } from "@mui/icons-material";
|
|
52
|
-
import {
|
|
49
|
+
import {
|
|
50
|
+
Alert,
|
|
51
|
+
AlertTitle,
|
|
52
|
+
Typography as Typography2
|
|
53
|
+
} from "@mui/material";
|
|
53
54
|
import { ButtonEx } from "@xylabs/react-button";
|
|
54
|
-
import
|
|
55
|
-
function ErrorAlert({
|
|
55
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
56
|
+
function ErrorAlert({
|
|
57
|
+
title = "Whoops! Something went wrong",
|
|
58
|
+
onCancel,
|
|
59
|
+
error = "An unknown error occurred",
|
|
60
|
+
errorContext,
|
|
61
|
+
scope,
|
|
62
|
+
...props
|
|
63
|
+
}) {
|
|
56
64
|
const finalScope = scope ?? errorContext;
|
|
57
|
-
return /* @__PURE__ */
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
top: 8
|
|
80
|
-
}
|
|
81
|
-
}, /* @__PURE__ */ React3.createElement(ExitIcon, {
|
|
82
|
-
fontSize: "small"
|
|
83
|
-
})) : null);
|
|
65
|
+
return /* @__PURE__ */ jsxs2(Alert, { severity: "error", ...props, children: [
|
|
66
|
+
/* @__PURE__ */ jsx3(AlertTitle, { children: title }),
|
|
67
|
+
finalScope ? /* @__PURE__ */ jsxs2("div", { children: [
|
|
68
|
+
/* @__PURE__ */ jsx3(Typography2, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Scope:" }),
|
|
69
|
+
/* @__PURE__ */ jsx3(Typography2, { variant: "caption", children: finalScope })
|
|
70
|
+
] }) : null,
|
|
71
|
+
/* @__PURE__ */ jsxs2("div", { children: [
|
|
72
|
+
/* @__PURE__ */ jsx3(Typography2, { variant: "caption", mr: 0.5, fontWeight: "bold", children: "Error:" }),
|
|
73
|
+
/* @__PURE__ */ jsx3(Typography2, { variant: "caption", children: typeof error === "string" ? error : error?.message })
|
|
74
|
+
] }),
|
|
75
|
+
onCancel ? /* @__PURE__ */ jsx3(
|
|
76
|
+
ButtonEx,
|
|
77
|
+
{
|
|
78
|
+
variant: "outlined",
|
|
79
|
+
size: "small",
|
|
80
|
+
onClick: onCancel,
|
|
81
|
+
position: "absolute",
|
|
82
|
+
style: { right: 8, top: 8 },
|
|
83
|
+
children: /* @__PURE__ */ jsx3(ExitIcon, { fontSize: "small" })
|
|
84
|
+
}
|
|
85
|
+
) : null
|
|
86
|
+
] });
|
|
84
87
|
}
|
|
85
|
-
__name(ErrorAlert, "ErrorAlert");
|
|
86
88
|
|
|
87
89
|
// src/components/ErrorRender/Render.tsx
|
|
88
90
|
import { FlexCol as FlexCol2 } from "@xylabs/react-flexbox";
|
|
89
|
-
import
|
|
90
|
-
|
|
91
|
+
import { useEffect } from "react";
|
|
92
|
+
import { Fragment, jsx as jsx4 } from "react/jsx-runtime";
|
|
93
|
+
function ErrorRender({
|
|
94
|
+
onCancel,
|
|
95
|
+
error,
|
|
96
|
+
noErrorDisplay = false,
|
|
97
|
+
customError = null,
|
|
98
|
+
children,
|
|
99
|
+
errorContext,
|
|
100
|
+
scope,
|
|
101
|
+
useLocation,
|
|
102
|
+
...props
|
|
103
|
+
}) {
|
|
91
104
|
const location = useLocation?.();
|
|
92
105
|
useEffect(() => {
|
|
93
106
|
if (location) {
|
|
94
|
-
location.state = {
|
|
95
|
-
from: {
|
|
96
|
-
pathname: globalThis.location.pathname
|
|
97
|
-
}
|
|
98
|
-
};
|
|
107
|
+
location.state = { from: { pathname: globalThis.location.pathname } };
|
|
99
108
|
}
|
|
100
|
-
}, [
|
|
101
|
-
location
|
|
102
|
-
]);
|
|
109
|
+
}, [location]);
|
|
103
110
|
useEffect(() => {
|
|
104
111
|
if (error) {
|
|
105
112
|
globalThis.rollbar?.error(error);
|
|
106
113
|
}
|
|
107
|
-
}, [
|
|
108
|
-
|
|
109
|
-
]);
|
|
110
|
-
return error ? /* @__PURE__ */ React4.createElement(FlexCol2, {
|
|
111
|
-
alignItems: "stretch",
|
|
112
|
-
...props
|
|
113
|
-
}, noErrorDisplay ? customError : /* @__PURE__ */ React4.createElement(FlexCol2, {
|
|
114
|
-
alignItems: "center",
|
|
115
|
-
...props
|
|
116
|
-
}, /* @__PURE__ */ React4.createElement(ErrorAlert, {
|
|
117
|
-
error,
|
|
118
|
-
errorContext,
|
|
119
|
-
onCancel,
|
|
120
|
-
scope
|
|
121
|
-
}))) : /* @__PURE__ */ React4.createElement(React4.Fragment, null, children);
|
|
114
|
+
}, [error]);
|
|
115
|
+
return error ? /* @__PURE__ */ jsx4(FlexCol2, { alignItems: "stretch", ...props, children: noErrorDisplay ? customError : /* @__PURE__ */ jsx4(FlexCol2, { alignItems: "center", ...props, children: /* @__PURE__ */ jsx4(ErrorAlert, { error, errorContext, onCancel, scope }) }) }) : /* @__PURE__ */ jsx4(Fragment, { children });
|
|
122
116
|
}
|
|
123
|
-
__name(ErrorRender, "ErrorRender");
|
|
124
117
|
|
|
125
118
|
// src/contexts/ErrorReporter/Provider.tsx
|
|
126
119
|
import { useRollbar } from "@rollbar/react";
|
|
127
|
-
import
|
|
120
|
+
import { useMemo } from "react";
|
|
128
121
|
|
|
129
122
|
// src/contexts/ErrorReporter/Context.ts
|
|
130
123
|
import { createContext } from "react";
|
|
131
124
|
var ErrorReporterContext = createContext({});
|
|
132
125
|
|
|
133
126
|
// src/contexts/ErrorReporter/Provider.tsx
|
|
134
|
-
|
|
127
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
128
|
+
var ErrorReporterProvider = ({ children, rollbar: rollbarProp }) => {
|
|
135
129
|
let rollbarFromHook;
|
|
136
130
|
try {
|
|
137
131
|
rollbarFromHook = useRollbar();
|
|
@@ -141,22 +135,19 @@ var ErrorReporterProvider = /* @__PURE__ */ __name(({ children, rollbar: rollbar
|
|
|
141
135
|
if (!rollbar) {
|
|
142
136
|
throw new Error("ErrorReporterProvider unable to find a Rollbar instance either passed as prop or from Provider");
|
|
143
137
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
}, children);
|
|
149
|
-
}, "ErrorReporterProvider");
|
|
138
|
+
const value = useMemo(() => ({ rollbar }), [rollbar]);
|
|
139
|
+
return /* @__PURE__ */ jsx5(ErrorReporterContext, { value, children });
|
|
140
|
+
};
|
|
150
141
|
|
|
151
142
|
// src/contexts/ErrorReporter/useErrorReporter.tsx
|
|
152
143
|
import { use } from "react";
|
|
153
|
-
var useErrorReporter =
|
|
144
|
+
var useErrorReporter = () => {
|
|
154
145
|
const context = use(ErrorReporterContext);
|
|
155
146
|
if (context === void 0) {
|
|
156
147
|
console.warn("useErrorReporter must be used within a ErrorReporterContext");
|
|
157
148
|
}
|
|
158
149
|
return context ?? {};
|
|
159
|
-
}
|
|
150
|
+
};
|
|
160
151
|
export {
|
|
161
152
|
ErrorAlert,
|
|
162
153
|
ErrorBoundary,
|
|
@@ -1 +1 @@
|
|
|
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\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}: Readonly<ErrorAlertProps<T>>) {\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>) {\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 // eslint-disable-next-line react-x/rules-of-hooks, react-hooks/rules-of-hooks\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 return <ErrorReporterContext value={{ rollbar }}>{children}</ErrorReporterContext>\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 { use } from 'react'\n\nimport { ErrorReporterContext } from './Context.ts'\n\n/** @deprecated use from @xylabs/react-error instead */\nexport const useErrorReporter = () => {\n const context = use(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,iBAA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GC,cAEE,gBAAAa,OAAA,cAACC,UAAAA;IAAQC,YAAW;IAAU,GAAGV;KAC/B,gBAAAQ,OAAA,cAACG,YAAAA;IAAWlB;IAAcI;IAA4BL;IAAoBM;SAKtF,gBAAAU,OAAA,cAAAA,OAAA,UAAA,MAAGZ,QAAAA;AACT;AAtCgBL;;;ACNhB,SAASqB,kBAAkB;AAE3B,OAAOC,YAAW;;;ACFlB,SAASC,qBAAqB;AAKvB,IAAMC,uBAAuBD,cAAyC,CAAC,CAAA;;;ADOvE,IAAME,wBAAiF,wBAAC,EAAEC,UAAUC,SAASC,YAAW,MAAE;AAC/H,MAAIC;AAEJ,MAAI;AAEFA,sBAAkBC,WAAAA;EACpB,QAAQ;EAAC;AAET,QAAMH,UAAUC,eAAeC;AAE/B,MAAI,CAACF,SAAS;AACZ,UAAM,IAAII,MAAM,gGAAA;EAClB;AAEA,SAAO,gBAAAC,OAAA,cAACC,sBAAAA;IAAqBC,OAAO;MAAEP;IAAQ;KAAID,QAAAA;AACpD,GAf8F;;;AEZ9F,SAASS,WAAW;AAKb,IAAMC,mBAAmB,6BAAA;AAC9B,QAAMC,UAAUC,IAAIC,oBAAAA;AACpB,MAAIF,YAAYG,QAAW;AACzBC,YAAQC,KAAK,6DAAA;EACf;AAEA,SAAOL,WAAW,CAAC;AACrB,GAPgC;","names":["Typography","FlexCol","React","Component","ErrorBoundary","Component","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","value","use","useErrorReporter","context","use","ErrorReporterContext","undefined","console","warn"]}
|
|
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\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}: Readonly<ErrorAlertProps<T>>) {\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>) {\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 // eslint-disable-next-line react-hooks/immutability\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, { useMemo } 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 // eslint-disable-next-line react-x/rules-of-hooks, react-hooks/rules-of-hooks\n rollbarFromHook = useRollbar()\n } catch { /* safely ignore if rollbar hook not available */ }\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 const value = useMemo(() => ({ rollbar }), [rollbar])\n\n return <ErrorReporterContext value={value}>{children}</ErrorReporterContext>\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 { use } from 'react'\n\nimport { ErrorReporterContext } from './Context.ts'\n\n/** @deprecated use from @xylabs/react-error instead */\nexport const useErrorReporter = () => {\n const context = use(ErrorReporterContext)\n if (context === undefined) {\n console.warn('useErrorReporter must be used within a ErrorReporterContext')\n }\n\n return context ?? {}\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,eAAe;AAExB,SAAgB,iBAAiB;AAwCrB,cAEE,YAFF;AAtBL,IAAM,gBAAN,cAA4B,UAAkD;AAAA,EACnF,YAAY,OAA2B;AACrC,UAAM,KAAK;AACX,SAAK,QAAQ,EAAE,OAAO,OAAU;AAAA,EAClC;AAAA,EAEA,OAAO,yBAAyB,OAAc;AAC5C,WAAO,EAAE,MAAM;AAAA,EACjB;AAAA,EAES,kBAAkB,OAAc,WAAsB;AAC7D,YAAQ,MAAM,GAAG,KAAK,KAAK,SAAS,EAAE;AAAA,EACxC;AAAA,EAES,SAAS;AAChB,QAAI,KAAK,MAAM,OAAO;AACpB,UAAI,KAAK,MAAM,mBAAmB;AAChC,eAAO,KAAK,MAAM,kBAAkB,KAAK,MAAM,KAAK;AAAA,MACtD;AACA,aACE,KAAK,MAAM,YACT,qBAAC,WACC;AAAA,4BAAC,cAAW,SAAQ,MAAK,mCAAqB;AAAA,QAC7C,KAAK,MAAM,SACV,qBAAC,cAAW,SAAQ,MAAK;AAAA;AAAA,UAEtB,KAAK,MAAM;AAAA,UAAM;AAAA,WAEpB;AAAA,QAEF,qBAAC,cAAW,SAAQ,SAAQ;AAAA;AAAA,UAEzB,KAAK,MAAM,OAAO;AAAA,UAAQ;AAAA,WAE7B;AAAA,SACF;AAAA,IAGN;AAEA,WAAO,KAAK,MAAM;AAAA,EACpB;AACF;;;AC9DA,SAAS,uBAAuB,+BAA+B;AAMtD,gBAAAA,YAAA;AADF,IAAM,sBAAiE,CAAC,UAAU;AACvF,SAAO,gBAAAA,KAAC,2BAAs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AW,CAAC;AACrB;","names":["jsx","Typography","jsx","jsxs","FlexCol","jsx","FlexCol","jsx"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyo-network/react-error",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.12",
|
|
4
4
|
"description": "Common React library for all XYO projects that use React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xyo",
|
|
@@ -36,47 +36,85 @@
|
|
|
36
36
|
},
|
|
37
37
|
"./package.json": "./package.json"
|
|
38
38
|
},
|
|
39
|
-
"module": "dist/browser/index.mjs",
|
|
40
|
-
"types": "dist/browser/index.d.ts",
|
|
41
39
|
"files": [
|
|
42
40
|
"dist",
|
|
43
|
-
"
|
|
41
|
+
"README.md"
|
|
44
42
|
],
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"@rollbar/react": "~1.0.0",
|
|
47
|
-
"@xylabs/react-button": "~7.1.17",
|
|
48
|
-
"@xylabs/react-error": "~7.1.17",
|
|
49
|
-
"@xylabs/react-flexbox": "~7.1.17",
|
|
50
|
-
"@xyo-network/payload-model": "~5.3.17"
|
|
51
|
-
},
|
|
52
43
|
"devDependencies": {
|
|
53
|
-
"@mui/icons-material": "
|
|
54
|
-
"@mui/material": "
|
|
55
|
-
"@
|
|
44
|
+
"@mui/icons-material": "^7.3.10",
|
|
45
|
+
"@mui/material": "^7.3.10",
|
|
46
|
+
"@opentelemetry/api": "^1.9.1",
|
|
47
|
+
"@opentelemetry/sdk-trace-base": "^2.7.0",
|
|
48
|
+
"@rollbar/react": "~1.0.0",
|
|
49
|
+
"@storybook/react-vite": "~10.3.5",
|
|
50
|
+
"@types/node": "~25.6.0",
|
|
56
51
|
"@types/react": "^19.2.14",
|
|
57
|
-
"@xylabs/
|
|
58
|
-
"@xylabs/
|
|
59
|
-
"@xylabs/
|
|
60
|
-
"@xylabs/
|
|
61
|
-
"@xylabs/
|
|
62
|
-
"
|
|
63
|
-
"react": "
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
52
|
+
"@xylabs/react-async-effect": "~7.1.20",
|
|
53
|
+
"@xylabs/react-button": "~7.1.20",
|
|
54
|
+
"@xylabs/react-dialogs": "~7.1.20",
|
|
55
|
+
"@xylabs/react-error": "~7.1.20",
|
|
56
|
+
"@xylabs/react-flexbox": "~7.1.20",
|
|
57
|
+
"@xylabs/react-promise": "~7.1.20",
|
|
58
|
+
"@xylabs/react-quick-tip-button": "~7.1.20",
|
|
59
|
+
"@xylabs/sdk-js": "^5.0.100",
|
|
60
|
+
"@xylabs/toolchain": "~7.11.9",
|
|
61
|
+
"@xylabs/tsconfig": "^7.11.9",
|
|
62
|
+
"@xylabs/tsconfig-dom": "^7.11.9",
|
|
63
|
+
"@xylabs/tsconfig-react": "~7.11.9",
|
|
64
|
+
"@xylabs/zod": "~5.0.100",
|
|
65
|
+
"@xyo-network/payload-model": "^5.5.1",
|
|
66
|
+
"async-mutex": "^0.5.0",
|
|
67
|
+
"axios": "^1.15.2",
|
|
68
|
+
"bn.js": "^5.2.3",
|
|
69
|
+
"bowser": "^2.14.1",
|
|
70
|
+
"buffer": "^6.0.3",
|
|
71
|
+
"chalk": "^5.6.2",
|
|
72
|
+
"esbuild": "~0.28.0",
|
|
73
|
+
"eslint": "^10.2.1",
|
|
74
|
+
"ethers": "^6.16.0",
|
|
75
|
+
"fast-deep-equal": "~3.1.3",
|
|
76
|
+
"js-cookie": "~3.0.5",
|
|
77
|
+
"pako": "^2.1.0",
|
|
78
|
+
"prop-types": "^15.8.1",
|
|
79
|
+
"react": "^19.2.5",
|
|
80
|
+
"react-dom": "^19.2.5",
|
|
81
|
+
"react-router-dom": "^7.14.2",
|
|
82
|
+
"rollbar": "~3.1.0",
|
|
83
|
+
"spark-md5": "~3.0.2",
|
|
84
|
+
"storybook": "^10.3.5",
|
|
68
85
|
"typescript": "^5.9.3",
|
|
69
|
-
"vite": "
|
|
86
|
+
"vite": "^8.0.10",
|
|
70
87
|
"zod": "^4.3.6"
|
|
71
88
|
},
|
|
72
89
|
"peerDependencies": {
|
|
73
|
-
"@mui/icons-material": "
|
|
74
|
-
"@mui/material": "
|
|
75
|
-
"
|
|
76
|
-
"react
|
|
77
|
-
"react-
|
|
78
|
-
"
|
|
79
|
-
"
|
|
90
|
+
"@mui/icons-material": "^7.3.10",
|
|
91
|
+
"@mui/material": "^7.3.10",
|
|
92
|
+
"@opentelemetry/sdk-trace-base": "^2.7.0",
|
|
93
|
+
"@rollbar/react": "~1.0.0",
|
|
94
|
+
"@xylabs/react-async-effect": "~7.1.20",
|
|
95
|
+
"@xylabs/react-button": "~7.1.20",
|
|
96
|
+
"@xylabs/react-error": "~7.1.20",
|
|
97
|
+
"@xylabs/react-flexbox": "~7.1.20",
|
|
98
|
+
"@xylabs/react-quick-tip-button": "~7.1.20",
|
|
99
|
+
"@xylabs/sdk-js": "^5.0.100",
|
|
100
|
+
"@xylabs/zod": "~5.0.100",
|
|
101
|
+
"@xyo-network/payload-model": "^5.5.1",
|
|
102
|
+
"async-mutex": "^0.5.0",
|
|
103
|
+
"bn.js": "^5.2.3",
|
|
104
|
+
"bowser": "^2.14.1",
|
|
105
|
+
"buffer": "^6.0.3",
|
|
106
|
+
"chalk": "^5.6.2",
|
|
107
|
+
"ethers": "^6.16.0",
|
|
108
|
+
"fast-deep-equal": "~3.1.3",
|
|
109
|
+
"js-cookie": "~3.0.5",
|
|
110
|
+
"pako": "^2.1.0",
|
|
111
|
+
"prop-types": "^15.8.1",
|
|
112
|
+
"react": "^19.2.5",
|
|
113
|
+
"react-dom": "^19.2.5",
|
|
114
|
+
"react-router-dom": "^7.14.2",
|
|
115
|
+
"rollbar": "~3.1.0",
|
|
116
|
+
"spark-md5": "~3.0.2",
|
|
117
|
+
"zod": "^4.3.6"
|
|
80
118
|
},
|
|
81
119
|
"peerDependenciesMeta": {
|
|
82
120
|
"rollbar": {
|
|
@@ -87,4 +125,4 @@
|
|
|
87
125
|
"access": "public"
|
|
88
126
|
},
|
|
89
127
|
"docs": "dist/docs.json"
|
|
90
|
-
}
|
|
128
|
+
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Alert, Button } from '@mui/material'
|
|
2
|
-
import type { Meta, StoryFn } from '@storybook/react-vite'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
|
|
5
|
-
import { ThrownErrorBoundary } from './ThrownErrorBoundary.tsx'
|
|
6
|
-
|
|
7
|
-
const StorybookEntry: Meta = {
|
|
8
|
-
component: ThrownErrorBoundary,
|
|
9
|
-
title: 'auth-service/ApiBoundary/ThrownErrorBoundary',
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const Thrower: React.FC = () => {
|
|
13
|
-
const [shouldThrow, setShouldThrow] = React.useState(false)
|
|
14
|
-
if (shouldThrow) {
|
|
15
|
-
throw new Error('Test Error')
|
|
16
|
-
}
|
|
17
|
-
return (
|
|
18
|
-
<Button onClick={() => {
|
|
19
|
-
setShouldThrow(true)
|
|
20
|
-
}}
|
|
21
|
-
>
|
|
22
|
-
Throw Error
|
|
23
|
-
</Button>
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const Template: StoryFn<typeof ThrownErrorBoundary> = ({ errorComponent }) => {
|
|
28
|
-
return (
|
|
29
|
-
<ThrownErrorBoundary errorComponent={errorComponent} boundaryName="StoryBook">
|
|
30
|
-
<Alert severity="info">Use React Dev Tools to trigger and error within the boundary</Alert>
|
|
31
|
-
<Thrower />
|
|
32
|
-
</ThrownErrorBoundary>
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const Default = Template.bind({})
|
|
37
|
-
Default.args = {}
|
|
38
|
-
|
|
39
|
-
const CustomErrorComponent = Template.bind({})
|
|
40
|
-
CustomErrorComponent.args = {
|
|
41
|
-
errorComponent: e => (
|
|
42
|
-
<Alert severity="error">
|
|
43
|
-
Using Custom Error Component with error:
|
|
44
|
-
{e.message}
|
|
45
|
-
</Alert>
|
|
46
|
-
),
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export { CustomErrorComponent, Default }
|
|
50
|
-
|
|
51
|
-
export default StorybookEntry
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ThrownErrorBoundaryProps } from '@xylabs/react-error'
|
|
2
|
-
import { ThrownErrorBoundary as ThrownErrorBoundaryBase } from '@xylabs/react-error'
|
|
3
|
-
import type { ModuleError } from '@xyo-network/payload-model'
|
|
4
|
-
import type { FC } from 'react'
|
|
5
|
-
import React from 'react'
|
|
6
|
-
|
|
7
|
-
export const ThrownErrorBoundary: FC<ThrownErrorBoundaryProps<ModuleError>> = (props) => {
|
|
8
|
-
return <ThrownErrorBoundaryBase<ModuleError> {...props} />
|
|
9
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
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: ThrownErrorBoundaryInner.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 }: Readonly<ThrownErrorBoundaryProps<T>>): React.JSX.Element {
|
|
70
|
-
const { rollbar: rollbarErrorReporter } = useErrorReporter()
|
|
71
|
-
let rollbarFromHook: Rollbar | undefined
|
|
72
|
-
// safely call the hook
|
|
73
|
-
try {
|
|
74
|
-
// eslint-disable-next-line react-x/rules-of-hooks, react-hooks/rules-of-hooks
|
|
75
|
-
rollbarFromHook = useRollbar()
|
|
76
|
-
} catch {}
|
|
77
|
-
return <ThrownErrorBoundaryInner<T> rollbar={rollbar ?? rollbarErrorReporter ?? rollbarFromHook} {...props} />
|
|
78
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ThrownErrorBoundary.tsx'
|
|
@@ -1,64 +0,0 @@
|
|
|
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
|
-
/** @deprecated use from @xylabs/react-error instead */
|
|
7
|
-
export interface ErrorBoundaryProps {
|
|
8
|
-
children: ReactNode
|
|
9
|
-
// fallback as a static ReactNode value
|
|
10
|
-
fallback?: ReactNode
|
|
11
|
-
// fallback element that can receive the error as a prop
|
|
12
|
-
fallbackWithError?: (error: Error) => ReactNode
|
|
13
|
-
scope?: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** @deprecated use from @xylabs/react-error instead */
|
|
17
|
-
export interface ErrorBoundaryState {
|
|
18
|
-
error?: Error
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** @deprecated use from @xylabs/react-error instead */
|
|
22
|
-
export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
23
|
-
constructor(props: ErrorBoundaryProps) {
|
|
24
|
-
super(props)
|
|
25
|
-
this.state = { error: undefined }
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
static getDerivedStateFromError(error: Error) {
|
|
29
|
-
return { error }
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
override componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
33
|
-
console.error(`${error}: ${errorInfo}`)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
override render() {
|
|
37
|
-
if (this.state.error) {
|
|
38
|
-
if (this.props.fallbackWithError) {
|
|
39
|
-
return this.props.fallbackWithError(this.state.error)
|
|
40
|
-
}
|
|
41
|
-
return (
|
|
42
|
-
this.props.fallback ?? (
|
|
43
|
-
<FlexCol>
|
|
44
|
-
<Typography variant="h1">Something went wrong.</Typography>
|
|
45
|
-
{this.props.scope && (
|
|
46
|
-
<Typography variant="h2">
|
|
47
|
-
[
|
|
48
|
-
{this.props.scope}
|
|
49
|
-
]
|
|
50
|
-
</Typography>
|
|
51
|
-
)}
|
|
52
|
-
<Typography variant="body1">
|
|
53
|
-
[
|
|
54
|
-
{this.state.error?.message}
|
|
55
|
-
]
|
|
56
|
-
</Typography>
|
|
57
|
-
</FlexCol>
|
|
58
|
-
)
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return this.props.children
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryFn } from '@storybook/react-vite'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import { ErrorAlert } from './ErrorAlert.tsx'
|
|
5
|
-
|
|
6
|
-
const StorybookEntry: Meta = {
|
|
7
|
-
argTypes: {},
|
|
8
|
-
component: ErrorAlert,
|
|
9
|
-
parameters: { docs: { page: null } },
|
|
10
|
-
title: 'error/ErrorAlert',
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const Template: StoryFn<typeof ErrorAlert> = (props) => {
|
|
14
|
-
return <ErrorAlert {...props} />
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const Default = Template.bind({})
|
|
18
|
-
Default.args = {}
|
|
19
|
-
|
|
20
|
-
const WithTitle = Template.bind({})
|
|
21
|
-
WithTitle.args = { title: 'Oh No!' }
|
|
22
|
-
|
|
23
|
-
const WithError = Template.bind({})
|
|
24
|
-
WithError.args = { error: 'An error happened' }
|
|
25
|
-
|
|
26
|
-
const WithScope = Template.bind({})
|
|
27
|
-
WithScope.args = { scope: 'Storybook' }
|
|
28
|
-
|
|
29
|
-
const WithErrorAndScope = Template.bind({})
|
|
30
|
-
WithErrorAndScope.args = { error: 'An error happened', scope: 'Storybook' }
|
|
31
|
-
|
|
32
|
-
const WithErrorAndScopeAndTitle = Template.bind({})
|
|
33
|
-
WithErrorAndScopeAndTitle.args = {
|
|
34
|
-
error: 'An error happened', scope: 'Storybook', title: 'Oh No!',
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export {
|
|
38
|
-
Default, WithError, WithErrorAndScope, WithErrorAndScopeAndTitle, WithScope, WithTitle,
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default StorybookEntry
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ExitToApp as ExitIcon } from '@mui/icons-material'
|
|
2
|
-
import type { AlertProps } from '@mui/material'
|
|
3
|
-
import {
|
|
4
|
-
Alert, AlertTitle, Typography,
|
|
5
|
-
} from '@mui/material'
|
|
6
|
-
import { ButtonEx } from '@xylabs/react-button'
|
|
7
|
-
import React from 'react'
|
|
8
|
-
|
|
9
|
-
export interface ErrorAlertProps<T = void> extends AlertProps {
|
|
10
|
-
error?: T | Error | string
|
|
11
|
-
/** @deprecated use scope instead */
|
|
12
|
-
errorContext?: string
|
|
13
|
-
onCancel?: () => void
|
|
14
|
-
scope?: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function ErrorAlert<T = void>({
|
|
18
|
-
title = 'Whoops! Something went wrong',
|
|
19
|
-
onCancel,
|
|
20
|
-
error = 'An unknown error occurred',
|
|
21
|
-
errorContext,
|
|
22
|
-
scope,
|
|
23
|
-
...props
|
|
24
|
-
}: Readonly<ErrorAlertProps<T>>) {
|
|
25
|
-
const finalScope = scope ?? errorContext
|
|
26
|
-
return (
|
|
27
|
-
<Alert severity="error" {...props}>
|
|
28
|
-
<AlertTitle>{title}</AlertTitle>
|
|
29
|
-
{finalScope
|
|
30
|
-
? (
|
|
31
|
-
<div>
|
|
32
|
-
<Typography variant="caption" mr={0.5} fontWeight="bold">
|
|
33
|
-
Scope:
|
|
34
|
-
</Typography>
|
|
35
|
-
<Typography variant="caption">{finalScope}</Typography>
|
|
36
|
-
</div>
|
|
37
|
-
)
|
|
38
|
-
: null}
|
|
39
|
-
<div>
|
|
40
|
-
<Typography variant="caption" mr={0.5} fontWeight="bold">
|
|
41
|
-
Error:
|
|
42
|
-
</Typography>
|
|
43
|
-
<Typography variant="caption">{typeof error === 'string' ? error : (error as Error)?.message}</Typography>
|
|
44
|
-
</div>
|
|
45
|
-
{onCancel
|
|
46
|
-
? (
|
|
47
|
-
<ButtonEx
|
|
48
|
-
variant="outlined"
|
|
49
|
-
size="small"
|
|
50
|
-
onClick={onCancel}
|
|
51
|
-
position="absolute"
|
|
52
|
-
style={{ right: 8, top: 8 }}
|
|
53
|
-
>
|
|
54
|
-
<ExitIcon fontSize="small" />
|
|
55
|
-
</ButtonEx>
|
|
56
|
-
)
|
|
57
|
-
: null}
|
|
58
|
-
</Alert>
|
|
59
|
-
)
|
|
60
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { FlexBoxProps } from '@xylabs/react-flexbox'
|
|
2
|
-
import type { ReactNode } from 'react'
|
|
3
|
-
import type { Location } from 'react-router-dom'
|
|
4
|
-
|
|
5
|
-
export type ErrorEx<T = void> = T extends void ? Error : T | Error
|
|
6
|
-
|
|
7
|
-
export interface ErrorRenderProps<T = void> extends FlexBoxProps {
|
|
8
|
-
customError?: ReactNode
|
|
9
|
-
error?: ErrorEx<T>
|
|
10
|
-
errorContext?: string
|
|
11
|
-
noErrorDisplay?: boolean
|
|
12
|
-
noReAuth?: boolean
|
|
13
|
-
onCancel?: () => void
|
|
14
|
-
scope?: string
|
|
15
|
-
useLocation?: () => Location
|
|
16
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { FlexCol } from '@xylabs/react-flexbox'
|
|
2
|
-
import React, { useEffect } from 'react'
|
|
3
|
-
|
|
4
|
-
import { ErrorAlert } from './ErrorAlert.tsx'
|
|
5
|
-
import type { ErrorRenderProps } from './Props.ts'
|
|
6
|
-
|
|
7
|
-
export function ErrorRender<T = void>({
|
|
8
|
-
onCancel,
|
|
9
|
-
error,
|
|
10
|
-
noErrorDisplay = false,
|
|
11
|
-
customError = null,
|
|
12
|
-
children,
|
|
13
|
-
errorContext,
|
|
14
|
-
scope,
|
|
15
|
-
useLocation,
|
|
16
|
-
...props
|
|
17
|
-
}: ErrorRenderProps<T>) {
|
|
18
|
-
const location = useLocation?.()
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
if (location) {
|
|
21
|
-
// ensure we end up at the same place we are now after logging in
|
|
22
|
-
location.state = { from: { pathname: globalThis.location.pathname } }
|
|
23
|
-
}
|
|
24
|
-
}, [location])
|
|
25
|
-
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
if (error) {
|
|
28
|
-
globalThis.rollbar?.error(error)
|
|
29
|
-
}
|
|
30
|
-
}, [error])
|
|
31
|
-
|
|
32
|
-
return error
|
|
33
|
-
? (
|
|
34
|
-
<FlexCol alignItems="stretch" {...props}>
|
|
35
|
-
{noErrorDisplay
|
|
36
|
-
? customError
|
|
37
|
-
: (
|
|
38
|
-
<FlexCol alignItems="center" {...props}>
|
|
39
|
-
<ErrorAlert error={error} errorContext={errorContext} onCancel={onCancel} scope={scope} />
|
|
40
|
-
</FlexCol>
|
|
41
|
-
)}
|
|
42
|
-
</FlexCol>
|
|
43
|
-
)
|
|
44
|
-
: <>{children}</>
|
|
45
|
-
}
|
package/src/components/index.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { Typography } from '@mui/material'
|
|
2
|
-
import type { Meta, StoryFn } from '@storybook/react-vite'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
import Rollbar from 'rollbar'
|
|
5
|
-
|
|
6
|
-
import { ErrorReporterProvider } from './Provider.tsx'
|
|
7
|
-
import { useErrorReporter } from './useErrorReporter.tsx'
|
|
8
|
-
|
|
9
|
-
const StorybookEntry = {
|
|
10
|
-
argTypes: {},
|
|
11
|
-
component: ErrorReporterProvider,
|
|
12
|
-
parameters: { docs: { page: null } },
|
|
13
|
-
title: 'auth-service/ErrorReporterProvider',
|
|
14
|
-
} as Meta<typeof ErrorReporterProvider>
|
|
15
|
-
|
|
16
|
-
const RollbarComponent = () => {
|
|
17
|
-
const { rollbar } = useErrorReporter()
|
|
18
|
-
const rollbarFound = typeof rollbar?.error === 'function'
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<Typography color={rollbarFound ? 'green' : 'red'}>
|
|
22
|
-
Rollbar instance
|
|
23
|
-
{rollbarFound ? '' : 'NOT'}
|
|
24
|
-
{' '}
|
|
25
|
-
found from context!
|
|
26
|
-
</Typography>
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const Template: StoryFn<typeof ErrorReporterProvider> = () => {
|
|
31
|
-
const rollbar = new Rollbar()
|
|
32
|
-
return (
|
|
33
|
-
<ErrorReporterProvider rollbar={rollbar}>
|
|
34
|
-
<RollbarComponent />
|
|
35
|
-
</ErrorReporterProvider>
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const Default = Template.bind({})
|
|
40
|
-
|
|
41
|
-
export { Default }
|
|
42
|
-
|
|
43
|
-
export default StorybookEntry
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { useRollbar } from '@rollbar/react'
|
|
2
|
-
import type { PropsWithChildren } from 'react'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
import type Rollbar from 'rollbar'
|
|
5
|
-
|
|
6
|
-
import { ErrorReporterContext } from './Context.ts'
|
|
7
|
-
|
|
8
|
-
/** @deprecated use from @xylabs/react-error instead */
|
|
9
|
-
export interface ErrorReporterProviderProps {
|
|
10
|
-
rollbar: Rollbar
|
|
11
|
-
}
|
|
12
|
-
/** @deprecated use from @xylabs/react-error instead */
|
|
13
|
-
export const ErrorReporterProvider: React.FC<PropsWithChildren<ErrorReporterProviderProps>> = ({ children, rollbar: rollbarProp }) => {
|
|
14
|
-
let rollbarFromHook: Rollbar | undefined
|
|
15
|
-
// safely call the hook
|
|
16
|
-
try {
|
|
17
|
-
// eslint-disable-next-line react-x/rules-of-hooks, react-hooks/rules-of-hooks
|
|
18
|
-
rollbarFromHook = useRollbar()
|
|
19
|
-
} catch {}
|
|
20
|
-
|
|
21
|
-
const rollbar = rollbarProp ?? rollbarFromHook
|
|
22
|
-
|
|
23
|
-
if (!rollbar) {
|
|
24
|
-
throw new Error('ErrorReporterProvider unable to find a Rollbar instance either passed as prop or from Provider')
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return <ErrorReporterContext value={{ rollbar }}>{children}</ErrorReporterContext>
|
|
28
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { use } from 'react'
|
|
2
|
-
|
|
3
|
-
import { ErrorReporterContext } from './Context.ts'
|
|
4
|
-
|
|
5
|
-
/** @deprecated use from @xylabs/react-error instead */
|
|
6
|
-
export const useErrorReporter = () => {
|
|
7
|
-
const context = use(ErrorReporterContext)
|
|
8
|
-
if (context === undefined) {
|
|
9
|
-
console.warn('useErrorReporter must be used within a ErrorReporterContext')
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return context ?? {}
|
|
13
|
-
}
|
package/src/contexts/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './ErrorReporter/index.ts'
|
package/src/global.d.ts
DELETED
package/src/index.ts
DELETED