From 9cae3ab4d68e0853671fb207fa9086d802b7990a Mon Sep 17 00:00:00 2001 From: Nikhil Saraf Date: Sun, 5 Nov 2023 06:28:47 +0530 Subject: [PATCH] formar --- packages/vinxi-server-functions/server-handler.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/vinxi-server-functions/server-handler.js b/packages/vinxi-server-functions/server-handler.js index e779c338..aa7342f8 100644 --- a/packages/vinxi-server-functions/server-handler.js +++ b/packages/vinxi-server-functions/server-handler.js @@ -10,7 +10,11 @@ export async function handleServerAction(event) { invariant(typeof serverReference === "string", "Invalid server action"); // This is the client-side case const [filepath, name] = serverReference.split("#"); - const action = (await import.meta.env.MANIFEST[import.meta.env.ROUTER_NAME].chunks[filepath].import())[name]; + const action = ( + await import.meta.env.MANIFEST[import.meta.env.ROUTER_NAME].chunks[ + filepath + ].import() + )[name]; const text = await new Promise((resolve) => { const requestBody = []; event.node.req.on("data", (chunks) => { @@ -32,7 +36,13 @@ export async function handleServerAction(event) { return JSON.stringify(response ?? null); } catch (x) { console.error(x); - return { error: x.message } + return new Response(JSON.stringify({ error: x.message }), { + status: 500, + headers: { + "Content-Type": "application/json", + "x-server-function": "error", + }, + }); } } else { throw new Error("Invalid request");