"use client";
import { Component, useState, type ReactNode } from "react";
import type { ClientErrorBoundaryFallbackProps } from "./types.js";
/**
* Check if an error is a network-related error
*/
function isNetworkError(error: Error): boolean {
return error.name === "NetworkError";
}
/**
* Network error fallback UI with retry functionality
* Shows a connection-specific message and allows retrying via page refresh
*/
function NetworkErrorFallback({
error,
reset,
}: ClientErrorBoundaryFallbackProps): ReactNode {
const [isRetrying, setIsRetrying] = useState(false);
const handleRetry = (): void => {
setIsRetrying(true);
// Refresh the page to retry the request
window.location.reload();
};
return (
{/* Simple cloud with x icon using CSS */}
☁
Connection Error
{error.message ||
"Unable to connect to the server. Please check your internet connection."}
);
}
/**
* Default fallback UI for root error boundary
* This is shown when an unhandled error bubbles up to the root
*/
function RootErrorFallback({
error,
reset,
}: ClientErrorBoundaryFallbackProps): ReactNode {
const isDev = process.env.NODE_ENV !== "production";
return (
Internal Server Error
An unexpected error occurred while processing your request.