Merge pull request #338 from yug1224/get-error-html

apply missing getErrorHtml to public and local timeline pages
pull/255/head
Dario Piotrowicz 2023-02-23 16:08:30 +00:00 zatwierdzone przez GitHub
commit 53a7142e71
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
5 zmienionych plików z 27 dodań i 11 usunięć

Wyświetl plik

@ -14,7 +14,9 @@ export const clientLoader = loader$<Promise<Client>, { DATABASE: D1Database }>(a
let client: Client | null = null let client: Client | null = null
try { try {
client = await getClientById(platform.DATABASE, client_id) client = await getClientById(platform.DATABASE, client_id)
} catch { } catch (e: unknown) {
const error = e as { stack: string; cause: string }
console.warn(error.stack, error.cause)
throw html(500, getErrorHtml('An error occurred while trying to fetch the client data, please try again later')) throw html(500, getErrorHtml('An error occurred while trying to fetch the client data, please try again later'))
} }
if (client === null) { if (client === null) {
@ -36,8 +38,9 @@ export const userLoader = loader$<
// TODO: eventually, verify the JWT with Access, however this // TODO: eventually, verify the JWT with Access, however this
// is not critical. // is not critical.
payload = access.getPayload(jwt.value) payload = access.getPayload(jwt.value)
} catch (err: unknown) { } catch (e: unknown) {
console.warn((err as { stack: unknown }).stack) const error = e as { stack: string; cause: string }
console.warn(error.stack, error.cause)
throw html(500, getErrorHtml('Failed to validate Access JWT')) throw html(500, getErrorHtml('Failed to validate Access JWT'))
} }

Wyświetl plik

@ -19,7 +19,9 @@ export const statusLoader = loader$<
try { try {
const statusResponse = await statusAPI.handleRequestGet(platform.DATABASE, params.statusId, domain, {} as Person) const statusResponse = await statusAPI.handleRequestGet(platform.DATABASE, params.statusId, domain, {} as Person)
statusText = await statusResponse.text() statusText = await statusResponse.text()
} catch { } catch (e: unknown) {
const error = e as { stack: string; cause: string }
console.warn(error.stack, error.cause)
throw html(500, getErrorHtml('An error occurred whilst retrieving the status data, please try again later')) throw html(500, getErrorHtml('An error occurred whilst retrieving the status data, please try again later'))
} }
if (!statusText) { if (!statusText) {
@ -36,7 +38,9 @@ export const statusLoader = loader$<
throw new Error(`No context present for status with ${params.statusId}`) throw new Error(`No context present for status with ${params.statusId}`)
} }
return { status, statusTextContent, context } return { status, statusTextContent, context }
} catch { } catch (e: unknown) {
const error = e as { stack: string; cause: string }
console.warn(error.stack, error.cause)
throw html(500, getErrorHtml('No context for the status has been found, please try again later')) throw html(500, getErrorHtml('No context for the status has been found, please try again later'))
} }
}) })

Wyświetl plik

@ -9,6 +9,7 @@ import { WildebeestLogo } from '~/components/MastodonLogo'
import { getCommitHash } from '~/utils/getCommitHash' import { getCommitHash } from '~/utils/getCommitHash'
import { InstanceConfigContext } from '~/utils/instanceConfig' import { InstanceConfigContext } from '~/utils/instanceConfig'
import { getDocumentHead } from '~/utils/getDocumentHead' import { getDocumentHead } from '~/utils/getDocumentHead'
import { getErrorHtml } from '~/utils/getErrorHtml/getErrorHtml'
export const instanceLoader = loader$< export const instanceLoader = loader$<
Promise<InstanceConfig>, Promise<InstanceConfig>,
@ -24,8 +25,10 @@ export const instanceLoader = loader$<
const results = await response.text() const results = await response.text()
const json = JSON.parse(results) as InstanceConfig const json = JSON.parse(results) as InstanceConfig
return json return json
} catch { } catch (e: unknown) {
throw html(500, 'An error occurred whilst retrieving the instance details') const error = e as { stack: string; cause: string }
console.warn(error.stack, error.cause)
throw html(500, getErrorHtml('An error occurred whilst retrieving the instance details'))
} }
}) })

Wyświetl plik

@ -5,6 +5,7 @@ import { DocumentHead, loader$ } from '@builder.io/qwik-city'
import StickyHeader from '~/components/StickyHeader/StickyHeader' import StickyHeader from '~/components/StickyHeader/StickyHeader'
import { getDocumentHead } from '~/utils/getDocumentHead' import { getDocumentHead } from '~/utils/getDocumentHead'
import { StatusesPanel } from '~/components/StatusesPanel/StatusesPanel' import { StatusesPanel } from '~/components/StatusesPanel/StatusesPanel'
import { getErrorHtml } from '~/utils/getErrorHtml/getErrorHtml'
export const statusesLoader = loader$<Promise<MastodonStatus[]>, { DATABASE: D1Database; domain: string }>( export const statusesLoader = loader$<Promise<MastodonStatus[]>, { DATABASE: D1Database; domain: string }>(
async ({ platform, html }) => { async ({ platform, html }) => {
@ -14,8 +15,10 @@ export const statusesLoader = loader$<Promise<MastodonStatus[]>, { DATABASE: D1D
const results = await response.text() const results = await response.text()
// Manually parse the JSON to ensure that Qwik finds the resulting objects serializable. // Manually parse the JSON to ensure that Qwik finds the resulting objects serializable.
return JSON.parse(results) as MastodonStatus[] return JSON.parse(results) as MastodonStatus[]
} catch { } catch (e: unknown) {
throw html(500, 'The public timeline is unavailable') const error = e as { stack: string; cause: string }
console.warn(error.stack, error.cause)
throw html(500, getErrorHtml('The public timeline is unavailable'))
} }
} }
) )

Wyświetl plik

@ -5,6 +5,7 @@ import { DocumentHead, loader$ } from '@builder.io/qwik-city'
import StickyHeader from '~/components/StickyHeader/StickyHeader' import StickyHeader from '~/components/StickyHeader/StickyHeader'
import { getDocumentHead } from '~/utils/getDocumentHead' import { getDocumentHead } from '~/utils/getDocumentHead'
import { StatusesPanel } from '~/components/StatusesPanel/StatusesPanel' import { StatusesPanel } from '~/components/StatusesPanel/StatusesPanel'
import { getErrorHtml } from '~/utils/getErrorHtml/getErrorHtml'
export const statusesLoader = loader$<Promise<MastodonStatus[]>, { DATABASE: D1Database; domain: string }>( export const statusesLoader = loader$<Promise<MastodonStatus[]>, { DATABASE: D1Database; domain: string }>(
async ({ platform, html }) => { async ({ platform, html }) => {
@ -14,8 +15,10 @@ export const statusesLoader = loader$<Promise<MastodonStatus[]>, { DATABASE: D1D
const results = await response.text() const results = await response.text()
// Manually parse the JSON to ensure that Qwik finds the resulting objects serializable. // Manually parse the JSON to ensure that Qwik finds the resulting objects serializable.
return JSON.parse(results) as MastodonStatus[] return JSON.parse(results) as MastodonStatus[]
} catch { } catch (e: unknown) {
throw html(500, 'The local timeline is unavailable') const error = e as { stack: string; cause: string }
console.warn(error.stack, error.cause)
throw html(500, getErrorHtml('The local timeline is unavailable'))
} }
} }
) )