@@ -9,6 +9,7 @@ import { BackgroundBeams } from '../../components/ui/background-beams';
99import { Card } from '../../components/Card' ;
1010import { toast } from 'sonner' ;
1111import { Lock , AlertTriangle , Hourglass , Copy , Download } from 'lucide-react' ;
12+ import { ErrorLogger } from '@/lib/errorLogger' ;
1213
1314interface SealStatus {
1415 id : string ;
@@ -29,6 +30,7 @@ function VaultPageClient({ id }: { id: string }) {
2930 const [ status , setStatus ] = useState < SealStatus | null > ( null ) ;
3031 const [ decryptedContent , setDecryptedContent ] = useState < string | null > ( null ) ;
3132 const [ error , setError ] = useState < string | null > ( null ) ;
33+ const [ errorDetails , setErrorDetails ] = useState < any > ( null ) ;
3234 const [ timeLeft , setTimeLeft ] = useState < number > ( 0 ) ;
3335
3436 useEffect ( ( ) => {
@@ -69,6 +71,7 @@ function VaultPageClient({ id }: { id: string }) {
6971 const keyA = globalThis . window . location . hash . substring ( 1 ) ;
7072 if ( ! keyA ) {
7173 setError ( 'Key A not found in URL. Invalid vault link.' ) ;
74+ setErrorDetails ( { reason : 'missing_key_a' , url : globalThis . window . location . href } ) ;
7275 return ;
7376 }
7477
@@ -82,6 +85,7 @@ function VaultPageClient({ id }: { id: string }) {
8285
8386 if ( ! blobData ) {
8487 setError ( 'Encrypted content not found' ) ;
88+ setErrorDetails ( { reason : 'missing_blob' , sealId : id } ) ;
8589 return ;
8690 }
8791
@@ -98,20 +102,26 @@ function VaultPageClient({ id }: { id: string }) {
98102 try {
99103 const content = new TextDecoder ( 'utf-8' , { fatal : true } ) . decode ( decrypted ) ;
100104 setDecryptedContent ( content ) ;
101- } catch {
105+ } catch ( decodeErr ) {
106+ console . error ( '[VAULT] UTF-8 decode failed:' , decodeErr ) ;
107+ ErrorLogger . log ( decodeErr , { component : 'Vault' , action : 'utf8_decode' , sealId : id } ) ;
102108 setError ( 'Decryption succeeded but content is corrupted' ) ;
109+ setErrorDetails ( { reason : 'utf8_decode_failed' , error : decodeErr instanceof Error ? decodeErr . message : String ( decodeErr ) } ) ;
103110 }
104111 } catch ( err ) {
105112 console . error ( '[VAULT] Decryption failed:' , err ) ;
106113 const errorMessage = err instanceof Error ? err . message : 'Unknown error' ;
114+ const errorStack = err instanceof Error ? err . stack : undefined ;
115+ ErrorLogger . log ( err , { component : 'Vault' , action : 'decrypt' , sealId : id } ) ;
107116 setError ( `Failed to decrypt message: ${ errorMessage } ` ) ;
117+ setErrorDetails ( { reason : 'decryption_failed' , error : errorMessage , stack : errorStack , sealId : id } ) ;
108118 }
109119 } , [ id ] ) ;
110120
111121 const fetchSealStatus = useCallback ( async ( ) => {
112122 try {
113123 const response = await fetch ( `/api/seal/${ id } ` ) ;
114- const data = await response . json ( ) as SealStatus & { encryptedBlob ?: string ; error ?: string | { code : string ; message : string } } ;
124+ const data = await response . json ( ) as SealStatus & { encryptedBlob ?: string ; error ?: string | { code : string ; message : string ; details ?: string ; debugInfo ?: any } } ;
115125
116126 console . log ( '[VAULT] API Response:' , response . status , data ) ;
117127
@@ -125,20 +135,32 @@ function VaultPageClient({ id }: { id: string }) {
125135 } else {
126136 // Handle both string and nested error object formats
127137 let errorMsg = 'Seal not found' ;
138+ let debugInfo = null ;
128139 if ( data . error ) {
129140 if ( typeof data . error === 'string' ) {
130141 errorMsg = data . error ;
131- } else if ( typeof data . error === 'object' && data . error . message ) {
132- errorMsg = data . error . message ;
142+ } else if ( typeof data . error === 'object' ) {
143+ errorMsg = data . error . message || errorMsg ;
144+ debugInfo = {
145+ code : data . error . code ,
146+ details : data . error . details ,
147+ debugInfo : data . error . debugInfo ,
148+ status : response . status
149+ } ;
133150 }
134151 }
135- console . error ( '[VAULT] Error:' , errorMsg , data ) ;
152+ console . error ( '[VAULT] Error:' , errorMsg , debugInfo , data ) ;
153+ ErrorLogger . log ( data . error , { component : 'Vault' , action : 'fetchStatus' , sealId : id , debugInfo } ) ;
136154 setError ( errorMsg ) ;
155+ setErrorDetails ( debugInfo ) ;
137156 }
138157 } catch ( err ) {
139158 console . error ( '[VAULT] Fetch failed:' , err ) ;
140159 const errorMessage = err instanceof Error ? err . message : 'Unknown error' ;
160+ const errorStack = err instanceof Error ? err . stack : undefined ;
161+ ErrorLogger . log ( err , { component : 'Vault' , action : 'fetchStatus' , sealId : id } ) ;
141162 setError ( `Failed to fetch seal: ${ errorMessage } ` ) ;
163+ setErrorDetails ( { reason : 'fetch_failed' , error : errorMessage , stack : errorStack , sealId : id } ) ;
142164 }
143165 } , [ id , decryptMessage ] ) ;
144166
@@ -192,7 +214,17 @@ function VaultPageClient({ id }: { id: string }) {
192214 < AlertTriangle className = "w-16 h-16 text-red-500 mx-auto mb-6" />
193215 < h1 className = "text-2xl sm:text-3xl font-bold mb-4 glow-text text-red-500 px-2" > VAULT ERROR</ h1 >
194216 < Card className = "mb-8 border-red-500/30" >
195- < p className = "text-red-400/90 font-mono" > { error } </ p >
217+ < p className = "text-red-400/90 font-mono mb-4" > { error } </ p >
218+ { errorDetails && (
219+ < details className = "text-left" >
220+ < summary className = "text-red-400/60 text-xs cursor-pointer hover:text-red-400/80 mb-2" >
221+ Debug Info (click to expand)
222+ </ summary >
223+ < pre className = "text-red-400/70 text-xs bg-black/30 p-3 rounded overflow-x-auto" >
224+ { JSON . stringify ( errorDetails , null , 2 ) }
225+ </ pre >
226+ </ details >
227+ ) }
196228 </ Card >
197229 < a href = "/" className = "cyber-button inline-block hover:shadow-[0_0_30px_rgba(255,0,0,0.4)] hover:border-red-500/50" >
198230 CREATE NEW SEAL
0 commit comments