UNPKG

nextjs-swagger-autogen

Version:

Auto-generate Swagger documentation for Next.js API routes

46 lines (45 loc) 2.46 kB
"use strict"; "use client"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SwaggerErrorBoundary = SwaggerErrorBoundary; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = require("react"); function SwaggerErrorBoundary({ children, fallback }) { const [hasError, setHasError] = (0, react_1.useState)(false); const [error, setError] = (0, react_1.useState)(null); (0, react_1.useEffect)(() => { const errorHandler = (event) => { setHasError(true); setError(event.error); console.error("Swagger UI Error:", event.error, event); }; window.addEventListener("error", errorHandler); return () => { window.removeEventListener("error", errorHandler); }; }, []); if (hasError) { return (fallback || ((0, jsx_runtime_1.jsxs)("div", { style: { padding: "2rem", textAlign: "center", backgroundColor: "#f8f9fa", border: "1px solid #dee2e6", borderRadius: "8px", margin: "1rem", }, children: [(0, jsx_runtime_1.jsx)("h2", { style: { color: "#dc3545", marginBottom: "1rem" }, children: "Unable to Load API Documentation" }), (0, jsx_runtime_1.jsx)("p", { style: { color: "#6c757d", marginBottom: "1rem" }, children: "There was an error loading the Swagger UI. This might be due to:" }), (0, jsx_runtime_1.jsxs)("ul", { style: { textAlign: "left", maxWidth: "500px", margin: "0 auto", color: "#6c757d", }, children: [(0, jsx_runtime_1.jsx)("li", { children: "Invalid OpenAPI specification" }), (0, jsx_runtime_1.jsx)("li", { children: "Network connectivity issues" }), (0, jsx_runtime_1.jsx)("li", { children: "Browser compatibility problems" })] }), (0, jsx_runtime_1.jsx)("button", { onClick: () => window.location.reload(), style: { marginTop: "1rem", padding: "0.5rem 1rem", backgroundColor: "#007bff", color: "white", border: "none", borderRadius: "4px", cursor: "pointer", }, children: "Reload Page" })] }))); } return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }); }