|
12 | 12 | import Chip from '$lib/components/Chip.svelte' |
13 | 13 | import HelpToggle from '$lib/components/HelpToggle.svelte' |
14 | 14 |
|
15 | | - type DownloadState = 'Downloading' | 'Recipients' | 'Ready' | 'Decrypting' | 'Done' | 'Fail' | 'IdentityMismatch' |
| 15 | + type DownloadState = 'Downloading' | 'Recipients' | 'Ready' | 'Decrypting' | 'Done' | 'Fail' | 'ServerError' | 'IdentityMismatch' |
16 | 16 |
|
17 | 17 | // public_identity() returns a Policy: { ts: number, con: [{t: string, v?: string}] } |
18 | 18 | function getSenderEmail(identity: any): string { |
|
110 | 110 | try { |
111 | 111 | const { FILEHOST_URL, PKG_URL } = await import('$lib/env') |
112 | 112 |
|
113 | | - const vk = await fetch(`${PKG_URL}/v2/sign/parameters`) |
114 | | - .then((r) => r.json()) |
115 | | - .then((j) => j.publicKey) |
| 113 | + const vkResp = await fetch(`${PKG_URL}/v2/sign/parameters`) |
| 114 | + if (!vkResp.ok) { |
| 115 | + if (vkResp.status >= 500) { |
| 116 | + downloadState = 'ServerError' |
| 117 | + return |
| 118 | + } |
| 119 | + throw new Error(`Failed to fetch parameters: ${vkResp.status}`) |
| 120 | + } |
| 121 | + const vk = (await vkResp.json()).publicKey |
116 | 122 |
|
117 | 123 | const response = await fetch(`${FILEHOST_URL}/filedownload/${uuid}`) |
118 | | - if (!response.ok) throw new Error(`Failed to download file: ${response.status}`) |
| 124 | + if (!response.ok) { |
| 125 | + if (response.status >= 500) { |
| 126 | + downloadState = 'ServerError' |
| 127 | + return |
| 128 | + } |
| 129 | + throw new Error(`Failed to download file: ${response.status}`) |
| 130 | + } |
119 | 131 |
|
120 | 132 | if (!response.body) throw new Error('Response body is null') |
121 | 133 | const { StreamUnsealer } = await import('@e4a/pg-wasm') |
|
253 | 265 | err = String(e) |
254 | 266 | if ((e as any)?.isDecryptionFailure) { |
255 | 267 | downloadState = 'IdentityMismatch' |
| 268 | + } else if (/status: 5\d\d/.test(err) || /status(?:Code)?\s*[=:]\s*5\d\d/.test(err)) { |
| 269 | + downloadState = 'ServerError' |
256 | 270 | } else { |
257 | 271 | downloadState = 'Fail' |
258 | 272 | } |
|
297 | 311 | <h2> |
298 | 312 | {#if downloadState === 'Fail'} |
299 | 313 | {$_('filesharing.decryptpanel.notFoundTitle')} |
| 314 | + {:else if downloadState === 'ServerError'} |
| 315 | + {$_('filesharing.decryptpanel.serverErrorTitle')} |
300 | 316 | {:else if downloadState === 'IdentityMismatch'} |
301 | 317 | {$_('filesharing.decryptpanel.identityMismatchTitle')} |
302 | 318 | {:else} |
|
398 | 414 | </div> |
399 | 415 | {/if} |
400 | 416 |
|
| 417 | + {:else if downloadState === 'ServerError'} |
| 418 | + <p class="error-description">{$_('filesharing.decryptpanel.serverErrorSubtitle')}</p> |
| 419 | + <p class="error-description">{@html $_('filesharing.decryptpanel.serverErrorMessage')}</p> |
| 420 | + |
401 | 421 | {:else if downloadState === 'Fail'} |
402 | 422 | <p class="error-description">{$_('filesharing.decryptpanel.notFoundSubtitle')}</p> |
403 | 423 | <p class="error-description">{@html $_('filesharing.decryptpanel.notFoundMessage')}</p> |
|
0 commit comments