fix(core): make instanceof on SDK error classes work across bundled copies (#2384)

This commit is contained in:
Felix Weinberger 2026-07-06 15:53:12 +01:00 • committed by GitHub
commit ce2f65db0e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -113,11 +113,12 @@ let challenged = false;
try {
await client.connect(firstTransport);
} catch (error) {
// Under `--legacy` the transport surfaces `UnauthorizedError` directly;
// under `mode: 'auto'` the version-negotiation probe is what got 401'd
// and wraps it in an EraNegotiationFailed `SdkError` whose `data.cause`
// is the original `UnauthorizedError`. Either way the auth driver has
// already run by the time we land here — DCR done, auth URL captured.
// Both `--legacy` and `mode: 'auto'` surface the original
// `UnauthorizedError` directly (the negotiation probe propagates it
// unchanged; older releases wrapped it as the `data.cause` of an
// EraNegotiationFailed `SdkError`, which the unwrap below still
// tolerates). Either way the auth driver has already run by the time we
// land here — DCR done, auth URL captured.
const root = error instanceof UnauthorizedError ? error : (error as { data?: { cause?: unknown } }).data?.cause;
if (!(root instanceof UnauthorizedError)) throw error;
challenged = true;