supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
965 stars 129 forks source link

No error details reported when a connection is refused #418

Closed hypherionmc closed 1 year ago

hypherionmc commented 1 year ago

Bug report

Describe the bug

When trying to connect to a PostgREST server and the connection gets refused (wrong port, unreachable host etc), no error is returned from the promise.

For example, when executing the following code:

const { data, error } = await sql.from('apikeys').select();

and a connection error occurs, it only shows the following details inside of error:

{
  message: 'FetchError: fetch failed',
  details: '',
  hint: '',
  code: ''
}

By modifying PostgrestBuilder.js line 152 from details: '' to details:${fetchError}`` I was able to get this output instead, showing me that the connection was refused:

details: TypeError: fetch failed
      at fetch (D:\coding\service\node_modules\undici\index.js:109:13)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at fetch (D:\coding\service\node_modules\@miniflare\core\src\standards\http.ts:883:19)
      at WebSocketPlugin.<anonymous> (D:\coding\service\node_modules\@miniflare\core\src\standards\http.ts:981:15)
      at fetch (D:\coding\service\node_modules\@miniflare\web-sockets\src\plugin.ts:44:22)
      at generateApiKey (C:\Users\HYPHER~1\AppData\Local\Temp\tmp-14568-8EAAC6s274Mq\src\clients\claptrack.ts:40:29)
      at C:\Users\HYPHER~1\AppData\Local\Temp\tmp-14568-8EAAC6s274Mq\src\routes\claptrackroutecontroller.ts:18:27
      at C:\Users\HYPHER~1\AppData\Local\Temp\tmp-14568-8EAAC6s274Mq\node_modules\hono\dist\middleware\cors\index.js:40:7
      at C:\Users\HYPHER~1\AppData\Local\Temp\tmp-14568-8EAAC6s274Mq\node_modules\hono\dist\hono.js:205:50
      at ServiceWorkerGlobalScope.[kDispatchFetch] (D:\coding\service\node_modules\@miniflare\core\src\standards\event.ts:385:13) {
    cause: Error: connect ECONNREFUSED ::1:8858
        at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
        at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
      errno: -4078,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '::1',
      port: 8858
    }
  }

If I missed something that can enable this, I'm sorry

Expected behavior

I expect the real error to be returned in some sort of way, for easier troubleshooting...

System information

Additional context

I have a local PostgreSQL and PostgREST server running for a development environment