feat: improve error handling
This commit is contained in:
1 parent
4b6878ffac
commit
e34cace14f
8 files changed
+39
-31
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ params, url }) {
|
||||
const post = await getClient(params.instance.toLowerCase()).getPost({
|
||||
id: Number(params.id),
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
|
||||
let max_depth = post.post_view.counts.comments > 100 ? 1 : 3
|
||||
|
||||
const thread = url.searchParams.get('thread')
|
||||
let parentId: number | undefined
|
||||
|
||||
if (thread) {
|
||||
parentId = Number(thread.split('.')[1])
|
||||
|
||||
if (!Number.isInteger(parentId)) {
|
||||
parentId = undefined
|
||||
}
|
||||
}
|
||||
|
||||
if (parentId) {
|
||||
max_depth = 10
|
||||
}
|
||||
|
||||
return {
|
||||
singleThread: parentId != undefined,
|
||||
post: post,
|
||||
streamed: {
|
||||
comments: getClient(params.instance.toLowerCase()).getComments({
|
||||
post_id: Number(params.id),
|
||||
type_: 'All',
|
||||
limit: 25,
|
||||
page: 1,
|
||||
max_depth: max_depth,
|
||||
saved_only: false,
|
||||
sort: 'Hot',
|
||||
auth: get(profile)?.jwt,
|
||||
parent_id: parentId,
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user