panva / openid-client

OAuth 2 / OpenID Connect Client API for JavaScript Runtimes
MIT License
1.83k stars 392 forks source link

Low-level errors during `Issuer.discover()` cause error without stack trace #596

Closed sybereal closed 1 year ago

sybereal commented 1 year ago

Describe the bug

Below-HTTP errors, e.g. connection reset, during Issuer.discover() throw errors without a useful stack trace. Example:

Error: read ECONNRESET
    at __node_internal_captureLargerStackTrace (node:internal/errors:478:5)
    at __node_internal_errnoException (node:internal/errors:608:12)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'read'
}

To Reproduce Issuer and Client configuration: N/A - Crash occurred before these could be constructed.

Steps to reproduce the behaviour:

  1. `await Issuer.discover("https://some-host-that-resets.com")

Expected behaviour The stack trace should include the call to Issuer.discover() and everything leading up to that. This is the case when the request is successful but a HTTP error, such as 404, is returned:

> await Issuer.discover('https://example.com')
Uncaught OPError: expected 200 OK, got: 404 Not Found
    at processResponse (/app/node_modules/openid-client/lib/helpers/process_response.js:41:11)
    at Issuer.discover (/app/node_modules/openid-client/lib/issuer.js:179:18)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async REPL2:1:33 {
  error: 'expected 200 OK, got: 404 Not Found'
}

Environment:

Additional context