mirror of
https://github.com/BradNut/personal-website-sveltekit
synced 2025-09-08 23:20:18 +00:00
Fix import max pages and error name conflict.
This commit is contained in:
parent
381dd1697f
commit
b92de5c112
2 changed files with 8 additions and 6 deletions
|
|
@ -1,14 +1,16 @@
|
|||
import { json, error } from '@sveltejs/kit';
|
||||
import { WALLABAG_MAX_PAGES } from '$env/static/private';
|
||||
import type { RequestHandler, RequestEvent } from './$types';
|
||||
import { fetchArticlesApi } from '$root/routes/api';
|
||||
|
||||
export const GET: RequestHandler = async ({ url, setHeaders }: RequestEvent) => {
|
||||
try {
|
||||
if (+url?.searchParams?.get('page') > WALLABAG_MAX_PAGES) {
|
||||
const page = url?.searchParams?.get('page') || '1';
|
||||
if (+page > +WALLABAG_MAX_PAGES) {
|
||||
throw new Error('Page does not exist');
|
||||
}
|
||||
const response = await fetchArticlesApi('get', `fetchArticles`, {
|
||||
page: url?.searchParams?.get('page') || '1'
|
||||
page
|
||||
});
|
||||
|
||||
if (response?.articles) {
|
||||
|
|
@ -26,8 +28,8 @@ export const GET: RequestHandler = async ({ url, setHeaders }: RequestEvent) =>
|
|||
|
||||
return json(response);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
throw error(error);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
throw error(404, 'Page does not exist');
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export type ArticlePageLoad = {
|
|||
|
||||
export const load: PageServerLoad = async ({ fetch, params }) => {
|
||||
const { page } = params;
|
||||
if (+page > WALLABAG_MAX_PAGES) {
|
||||
if (+page > +WALLABAG_MAX_PAGES) {
|
||||
throw error(404, {
|
||||
message: 'Not found'
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue