Skip to content

Server functions do not set content-type header when an error is returned #4209

@spencewenski

Description

@spencewenski

Describe the bug
I'm using a custom error for my server functions and I'm setting type Encoder = leptos::server_fn::codec::JsonEncoding in my impl FromServerFnError. I would expect this to set the content-type: application/json header like leptos does for successful API responses, but the header is not set at all. I noticed that this also impacts the built-in ServerFnError -- I would expect it to set the header to text/plain, but it's missing.

Leptos Dependencies

Leptos 0.8.6 and the latest main branch. Example repro: spencewenski@3cd8c37

To Reproduce
Steps to reproduce the behavior:

  1. Update a server function to return an error. In the above repro, clear_server_count is updated.
  2. Run the counter_isomorphic example in in the above repro.
  3. Click the Clear button
  4. Observe that the response does not include the content-type.

Screenshots

Image

Next Steps

  • I will make a PR
  • I would like to make a PR, but need help getting started
  • I want someone else to take the time to fix this
  • This is a low priority for me and is just shared for your information

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions