mirror of
https://github.com/jcreek/SvelteKitSaasBoilerplate.git
synced 2026-07-14 11:33:49 +00:00
refactor(#65): move scope of logged params
Type defs added where relevent
This commit is contained in:
@@ -3,25 +3,35 @@ import { getActiveProductsWithPrices } from '$lib/utils/supabase/admin';
|
|||||||
import logger from '$lib/utils/logger/logger';
|
import logger from '$lib/utils/logger/logger';
|
||||||
|
|
||||||
export const GET = async ({ url }) => {
|
export const GET = async ({ url }) => {
|
||||||
|
const limitParam = url.searchParams.get('limit');
|
||||||
|
const offsetParam = url.searchParams.get('offset');
|
||||||
try {
|
try {
|
||||||
const limitParam = url.searchParams.get('limit');
|
|
||||||
const offsetParam = url.searchParams.get('offset');
|
|
||||||
|
|
||||||
const limit = limitParam ? parseInt(limitParam, 10) : 10;
|
const limit = limitParam ? parseInt(limitParam, 10) : 10;
|
||||||
const offset = offsetParam ? parseInt(offsetParam, 10) : 0;
|
const offset = offsetParam ? parseInt(offsetParam, 10) : 0;
|
||||||
|
|
||||||
const { products, count } = await getActiveProductsWithPrices(limit, offset);
|
const { products, count } = await getActiveProductsWithPrices(limit, offset);
|
||||||
|
|
||||||
return json({ products, count });
|
return json({ products, count });
|
||||||
} catch (error) {
|
} catch (error: unknown) {
|
||||||
logger.error('Failed to fetch products', {
|
if (error instanceof Error) {
|
||||||
error: error.message,
|
logger.error('Failed to fetch products', {
|
||||||
stack: error.stack,
|
error: error.message,
|
||||||
params: {
|
stack: error.stack,
|
||||||
limit: limitParam,
|
params: {
|
||||||
offset: offsetParam
|
limit: limitParam,
|
||||||
}
|
offset: offsetParam
|
||||||
});
|
}
|
||||||
return json({ error: error.message }, { status: 500 });
|
});
|
||||||
|
return json({ error: error.message }, { status: 500 });
|
||||||
|
} else {
|
||||||
|
logger.error('Failed to fetch products', {
|
||||||
|
error,
|
||||||
|
params: {
|
||||||
|
limit: limitParam,
|
||||||
|
offset: offsetParam
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return json({ error }, { status: 500 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user