T
TanStack10mo ago
exotic-emerald

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,
}),
)
})
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,
})
})
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.
2 Replies
unwilling-turquoise
unwilling-turquoise10mo ago
GitHub
Start: createServerFn cannot return raw response objects · Issue #2...
Which project does this relate to? Start Describe the bug Server functions should able to return Raw Response objects. Your Example Website or App https://github.com/nekochan0122/tanstack-start-ret...
exotic-emerald
exotic-emeraldOP10mo ago
thanks @millu

Did you find this page helpful?