@progress/sitefinity-nextjs-sdk
Version:
Provides OOB widgets developed using the Next.js framework, which includes an abstraction layer for Sitefinity communication. Additionally, it offers an expanded API, typings, and tools for further development and integration.
34 lines (33 loc) • 1.32 kB
JavaScript
'use client'; // Error boundaries must be Client Components
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { WidgetExecutionError } from '../widgets/error/widget-execution-error-component';
class ErrorBoundaryCustomHandler extends React.Component {
constructor(props) {
super(props);
this.state = { error: null };
}
static getDerivedStateFromError(error) {
return { error };
}
render() {
if (this.state.error) {
if (this.props.context.requestContext.isEdit) {
const errorProps = {
context: this.props.context,
error: this.state.error.message + '\n' + this.state.error.stack
};
const element = React.createElement(WidgetExecutionError, errorProps);
return (element);
}
if ((this.state.error?.digest ?? this.state.error?.message)?.startsWith('NEXT_HTTP_ERROR_FALLBACK')) {
throw this.state.error;
}
return (_jsx(_Fragment, {}));
}
return this.props.children;
}
}
export function ErrorBoundaryCustom({ children, context }) {
return (_jsx(ErrorBoundaryCustomHandler, { context: context, children: children }));
}