Files
authentik/website/docusaurus-theme/theme/DocCardList/ErrorBoundary.tsx
Dominic R 96eb8dda0f website: Glossary (#16007)
* website: Glossary

fix minor issues

wip

Apply suggestion from @dominic-r

Signed-off-by: Dominic R <dominic@sdko.org>

anchor to param

wip

wip

at least the lockfile changes now

sure

a-z first as tana asked

idk why i switched in the first place

wip

wip

lock

lockfiles are hard

wip

please work

no have?

Revert "no have?"

This reverts commit 743dbc1bc2900eedcc2c93af248e6afdec3688a3.

* changed to sentence-case capitalization

---------

Co-authored-by: Tana M Berry <tana@goauthentik.io>
2025-12-02 21:36:51 -05:00

77 lines
2.2 KiB
TypeScript

import React, { Component, ErrorInfo, ReactNode } from "react";
interface ErrorBoundaryProps {
children: ReactNode;
fallback?: ReactNode;
}
interface ErrorBoundaryState {
hasError: boolean;
error?: Error;
}
/**
* Error boundary component for gracefully handling errors in DocCardList components.
* Provides a fallback UI when errors occur during rendering or data processing.
*/
export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
constructor(props: ErrorBoundaryProps) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error: Error): ErrorBoundaryState {
return { hasError: true, error };
}
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
console.error("DocCardList Error Boundary caught an error:", error, errorInfo);
}
render() {
if (this.state.hasError) {
// Custom fallback UI
if (this.props.fallback) {
return this.props.fallback;
}
// Default fallback UI
return (
<div className="alert alert--danger margin-bottom--md">
<h4>Failed to load content</h4>
<p>
There was an error loading the documentation cards. Please try refreshing
the page.
</p>
<details className="margin-top--sm">
<summary>Error details</summary>
<pre className="margin-top--sm">
{this.state.error?.message || "Unknown error occurred"}
</pre>
</details>
</div>
);
}
return this.props.children;
}
}
/**
* Higher-order component wrapper for adding error boundary to any component
*/
export function withErrorBoundary<P extends object>(
Component: React.ComponentType<P>,
fallback?: ReactNode,
) {
return function WrappedComponent(props: P) {
return (
<ErrorBoundary fallback={fallback}>
<Component {...props} />
</ErrorBoundary>
);
};
}
export default ErrorBoundary;