Skip to content

Why is data an empty object for a 204 response? #1868

Closed
@mhuttner

Description

@mhuttner

I ran into this issue for an api call that may return 204.

If i check the returned data i expect it to be null

const { data } = await client.GET("/api/route/204");
if (data === null) {
 // do something
}
const { field} = data;

But this library explicitly sets the data to be an empty object?!

// handle empty content
// note: we return `{}` because we want user truthy checks for `.data` or `.error` to succeed
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
return response.ok ? { data: {}, response } : { error: {}, response };
}

Is there a reason for this?
This also breaks the type system, because it expects data to be the full object, null or undefined but not {}.

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