TanStackT
TanStack14mo ago
2 replies
sad-indigo

returning `Response` in `createServerFn`, is it supported?

Should the following code work?

Option 1:
export const signIn = createServerFn({ method: 'POST' })
  .handler(async () => {
    const event = getEvent()
    return sendWebResponse(
      event,
      new Response(JSON.stringify({ hello: 'world' }), {
        status: 422,
      }),
    )
  })


or

Option 2:
export const signIn = createServerFn({ method: 'POST' }).handler(async () => {
  return new Response(JSON.stringify({ hello: 'world' }), {
    status: 422,
  })
})


Option 2 seems to work(i.e. sending the right response code) but the server crashes after that.

Option 1 flat out doesn't work. It still responds with
200
.
Was this page helpful?