Skip to content

Commit

Permalink
oidc/init: include cause in re-thrown errors (#1393)
Browse files Browse the repository at this point in the history
This makes logged errors more useful.

Before:

```
attempted to log Sentry exception in development:
Error: Failed to configure OpenID Connect client: TypeError: fetch failed
    at initClient (/home/user/workspaces/odk/backend/lib/util/oidc.js:123:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async /home/user/workspaces/odk/backend/lib/resources/oidc.js:108:22
```

After:

```
attempted to log Sentry exception in development:
Error: Failed to configure OpenID Connect client
    at initClient (/home/user/workspaces/odk/backend/lib/util/oidc.js:123:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async /home/user/workspaces/odk/backend/lib/resources/oidc.js:108:22 {
  [cause]: TypeError: fetch failed
      at node:internal/deps/undici/undici:13484:13
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
      at async discovery (file:///home/user/workspaces/odk/backend/node_modules/openid-client/build/index.js:151:16)
      at async initClient (/home/user/workspaces/odk/backend/lib/util/oidc.js:65:20)
      at async /home/user/workspaces/odk/backend/lib/resources/oidc.js:108:22 {
    [cause]: Error: connect ECONNREFUSED 127.0.0.1:9898
        at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1615:16) {
      errno: -111,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '127.0.0.1',
      port: 9898
    }
  }
}
```
  • Loading branch information
alxndrsn authored Feb 21, 2025
1 parent c9479e0 commit c547dfc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/util/oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ async function initClient() {
});

return client;
} catch (err) {
} catch (cause) {
// N.B. don't include the config here - it might include the client secret, perhaps in the wrong place.
throw new Error(`Failed to configure OpenID Connect client: ${err}`);
throw new Error('Failed to configure OpenID Connect client', { cause });
}
}

Expand Down

0 comments on commit c547dfc

Please sign in to comment.