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
try {
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'))
}
if (client === null) {
@ -36,8 +38,9 @@ export const userLoader = loader$<
// TODO: eventually, verify the JWT with Access, however this
// is not critical.
payload = access.getPayload(jwt.value)
} catch (err: unknown) {
console.warn((err as { stack: unknown }).stack)
} catch (e: unknown) {
const error = e as { stack: string; cause: string }
console.warn(error.stack, error.cause)
throw html(500, getErrorHtml('Failed to validate Access JWT'))
}

Wyświetl plik

@ -19,7 +19,9 @@ export const statusLoader = loader$<
try {
const statusResponse = await statusAPI.handleRequestGet(platform.DATABASE, params.statusId, domain, {} as Person)
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'))
}
if (!statusText) {
@ -36,7 +38,9 @@ export const statusLoader = loader$<
throw new Error(`No context present for status with ${params.statusId}`)
}
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'))
}
})

Wyświetl plik

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

Wyświetl plik

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