getTodo(id) is our application helper. It returns a todo with id, task, and completed, or null when it doesn't exist.
error sets a status and stops loading. It throws for you; don't catch it or write throw error(...).
import { getTodo } from '#lib/server/db.js';
import { error } from '@sveltejs/kit';
export async function load({ params }) {
const todo = await getTodo(params.id);
if (!todo) error(404, 'Todo not found');
return { todo };
}