supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.

Home Page:https://supabase.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

statusText returns as empty string

pfeffer629 opened this issue · comments

Bug report

Describe the bug

I have tested upsert and insert, and upon success, receive this response:

{error: null, data: null, count: null, status: 201, statusText: ''}

I am trying to use statusText to determine whether a row has been created or updated.

To Reproduce

  async function createUser() {
    const res = await supabase
      .from("users")
      .insert(
        { username: username },
      );

    if (res.error) {
      throw res.error;
    }
    console.log(res)
  }

Expected behavior

statusText returns information as per documentation
Screen Shot 2023-02-22 at 10 56 38 AM

System information

  • macOS
  • Brave
  • supabase-js: [^2.2.2]
  • Node.js: [18.4.0]

I transferred this over to Postgrest-js.
I don't see any code in Postgrest-js to handle generating statusText for 201 responses like it does for 200 and 204 responses.
So either the code (and all clients?) need to add statusText for 201, or the documentation needs to change (less optimal as this user's case wants to use that text).

The status is retrieved directly from the PostgREST response, and statusText comes from fetch I believe. But I can't reproduce this on Node 18.4.0.

Are you also seeing this on 200 responses (e.g. when doing .select())? Also, is this code running in Node or in the browser? It'd also help if you have an example GitHub repo where I can try to reproduce this.

I was mistaken on status for 200, I saw in the code postgrest-js seems to add "OK" to some requests without results...

if (error && this.allowEmpty && error?.details?.includes('Results contain 0 rows')) {

But did not really study what it was up to and assumed it added OK on successful requests. The OP was doing an insert with no response coming back.

The response on insert:
image

Note the OP is commenting on Supabase's docs which say "Created" is returned.
image

Seems like then the documentation needs to be updated as it implies there is a statusText with meaning.

But need to confirm there is no status supposed to be returned as in docs.

All my requests are being sent through the browser.

Further context on my use case for statusText: on upserts, the status code returns as 201 regardless of whether it is an insert or an update (instead of 204).

IMHO, I believe statusText could be inferred from the status code and error messages, in which case, simply removing statusText and updating the documentation seems like a good solution.