Incorrect type for Promise: the Promise did not resolve to 'Response'

For Workes & Pages, what is the name of the domain?

local

What is the issue or error you’re encountering

Uncaught TypeError TypeError: Incorrect type for Promise: the Promise did not resolve to ‘Response’.

What steps have you taken to resolve the issue?

This program working fine, supabase procedure Send working fine, but Worker return error

export default {
     async fetch(request, env, ctx) {
     ...
      reqBody = await readRequestBody(request);
      const supabase = createClient(`${URL}`, `${KEY}`);
      await supabase.rpc("send", { txt: JSON.parse(reqBody).txt })  
      .then((ret)=>{
        return new Response(JSON.stringify({ count: ret.count, data: ret.data, error: ret.error, status: ret.status, statusText: ret.statusText }), {
          headers: {
            "content-type": "application/json",
          },
        });
      })

If I understand I return control to Cloudflare worker before branch inside Then working. But how to correctly rebuild this worker?

await supabase.rpc("send", { txt: JSON.parse(reqBody).txt })  
  .then((ret)=>{
    return new Response(JSON.stringify({ count: ret.count, data: ret.data, error: ret.error, status: ret.status, statusText: ret.statusText }), {
      headers: {
        "content-type": "application/json",
      },
    });
  })

This code isn’t actually returning anything at all. Your return new Response is in the then callback, but the await supabase... line doesn’t actually return anything.

You’ll either want to do something like this:

const results = await supabase.rpc(...);
return new Response(...);

or instead of await-ing your supabase.rpc(...).then(...) line, return it.

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.