diff --git a/packages/start/src/client-runtime/fetcher.tsx b/packages/start/src/client-runtime/fetcher.tsx index 1e4ef342bf..7f01e8169f 100644 --- a/packages/start/src/client-runtime/fetcher.tsx +++ b/packages/start/src/client-runtime/fetcher.tsx @@ -133,20 +133,10 @@ async function handleResponseErrors(response: Response) { return await response.text() })() - const message = `Request failed with status ${response.status}` - - if (isJson) { - throw new Error( - JSON.stringify({ - message, - body, - }), - ) - } else { - throw new Error( - [message, `${JSON.stringify(body, null, 2)}`].join('\n\n'), - ) - } + const defaultMessage = `Request failed with status ${response.status}` + const message = body?.message || body || defaultMessage + + throw new Error(message) } return response diff --git a/packages/start/src/server-handler/index.tsx b/packages/start/src/server-handler/index.tsx index 0e4dc04b2f..1605043903 100644 --- a/packages/start/src/server-handler/index.tsx +++ b/packages/start/src/server-handler/index.tsx @@ -143,17 +143,20 @@ export async function handleServerRequest(request: Request, event?: H3Event) { return redirectOrNotFoundResponse(error) } - console.error('Server Fn Error!') - console.error(error) - console.info() - - return new Response(JSON.stringify(error), { - status: 500, - headers: { - 'Content-Type': 'application/json', - [serverFnReturnTypeHeader]: 'error', + return new Response( + error instanceof Error + ? error.toString() + : JSON.stringify({ + message: error?.message ?? 'Internal Server Error', + }), + { + status: 500, + headers: { + 'Content-Type': 'application/json', + [serverFnReturnTypeHeader]: 'error', + }, }, - }) + ) } })()