import type { Handle, HandleServerError } from "@sveltejs/kit";

export const handleError: HandleServerError = async ({ error, event }) => {
    console.log("[-] Running error middleware for : ", event.url.pathname);
    console.log(error);
    return { message: (error as Error).message ?? "Internal Server Error" };
};

export const middleware: Handle = async ({ event, resolve }) => {
    event.locals.flowId ||= crypto.randomUUID();
    console.log("[+] Running middleware for : ", event.url.pathname);
    return resolve(event);
};

export const handle = middleware;
