Spaces:
Sleeping
Sleeping
File size: 6,142 Bytes
f871fed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
'use client'
import { useState } from 'react'
import { Card } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from '@/components/ui/collapsible'
import { Database, Server, ChevronDown, ExternalLink } from 'lucide-react'
import { ConnectionError } from '@/lib/types/config'
interface ConnectionErrorOverlayProps {
error: ConnectionError
onRetry: () => void
}
export function ConnectionErrorOverlay({
error,
onRetry,
}: ConnectionErrorOverlayProps) {
const [showDetails, setShowDetails] = useState(false)
const isApiError = error.type === 'api-unreachable'
return (
<div
className="fixed inset-0 bg-background z-50 flex items-center justify-center p-4"
role="alert"
aria-live="assertive"
aria-atomic="true"
>
<Card className="max-w-2xl w-full p-8 space-y-6">
{/* Error icon and title */}
<div className="flex items-center gap-4">
{isApiError ? (
<Server className="w-12 h-12 text-destructive" aria-hidden="true" />
) : (
<Database className="w-12 h-12 text-destructive" aria-hidden="true" />
)}
<div>
<h1 className="text-2xl font-bold" id="error-title">
{isApiError
? 'Unable to Connect to API Server'
: 'Database Connection Failed'}
</h1>
<p className="text-muted-foreground">
{isApiError
? 'The Open Notebook API server could not be reached'
: 'The API server is running, but the database is not accessible'}
</p>
</div>
</div>
{/* Troubleshooting instructions */}
<div className="space-y-4 border-l-4 border-primary pl-4">
<h2 className="font-semibold">This usually means:</h2>
<ul className="list-disc list-inside space-y-2 text-sm">
{isApiError ? (
<>
<li>The API server is not running</li>
<li>The API server is running on a different address</li>
<li>Network connectivity issues</li>
</>
) : (
<>
<li>SurrealDB is not running</li>
<li>Database connection settings are incorrect</li>
<li>Network issues between API and database</li>
</>
)}
</ul>
<h2 className="font-semibold mt-4">Quick fixes:</h2>
{isApiError ? (
<div className="space-y-2 text-sm bg-muted p-4 rounded">
<p className="font-medium">Set the API_URL environment variable:</p>
<code className="block bg-background p-2 rounded text-xs">
# For Docker:
<br />
docker run -e API_URL=http://your-host:5055 ...
<br />
<br />
# For local development (.env file):
<br />
API_URL=http://localhost:5055
</code>
</div>
) : (
<div className="space-y-2 text-sm bg-muted p-4 rounded">
<p className="font-medium">Check if SurrealDB is running:</p>
<code className="block bg-background p-2 rounded text-xs">
# For Docker:
<br />
docker compose ps | grep surrealdb
<br />
docker compose logs surrealdb
</code>
</div>
)}
</div>
{/* Documentation link */}
<div className="text-sm">
<p>For detailed setup instructions, see:</p>
<a
href="https://github.com/lfnovo/open-notebook"
target="_blank"
rel="noopener noreferrer"
className="text-primary hover:underline inline-flex items-center gap-1"
>
Open Notebook Documentation
<ExternalLink className="w-4 h-4" />
</a>
</div>
{/* Collapsible technical details */}
{error.details && (
<Collapsible open={showDetails} onOpenChange={setShowDetails}>
<CollapsibleTrigger asChild>
<Button variant="ghost" size="sm" className="w-full justify-between">
<span>Show Technical Details</span>
<ChevronDown
className={`w-4 h-4 transition-transform ${
showDetails ? 'rotate-180' : ''
}`}
/>
</Button>
</CollapsibleTrigger>
<CollapsibleContent className="pt-4">
<div className="space-y-2 text-sm bg-muted p-4 rounded font-mono">
{error.details.attemptedUrl && (
<div>
<strong>Attempted URL:</strong> {error.details.attemptedUrl}
</div>
)}
{error.details.message && (
<div>
<strong>Message:</strong> {error.details.message}
</div>
)}
{error.details.technicalMessage && (
<div>
<strong>Technical Details:</strong>{' '}
{error.details.technicalMessage}
</div>
)}
{error.details.stack && (
<div>
<strong>Stack Trace:</strong>
<pre className="mt-2 overflow-x-auto text-xs">
{error.details.stack}
</pre>
</div>
)}
</div>
</CollapsibleContent>
</Collapsible>
)}
{/* Retry button */}
<div className="pt-4 border-t">
<Button onClick={onRetry} className="w-full" size="lg">
Retry Connection
</Button>
<p className="text-xs text-muted-foreground text-center mt-2">
Press R or click the button to retry
</p>
</div>
</Card>
</div>
)
}
|