Fix import max pages and error name conflict.

This commit is contained in:
Bradley Shellnut 2023-02-14 17:56:07 -08:00
parent 381dd1697f
commit b92de5c112
2 changed files with 8 additions and 6 deletions

View file

@ -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');
}
};

View file

@ -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'
});