Skip to content

fix: respond 500 instead of crashing when login initiation fails - #15

Merged
cuzzlor merged 1 commit into
chore/npm-auditfrom
fix/login-unhandled-rejection
Aug 16, 2026
Merged

cuzzlor merged 1 commit into
chore/npm-auditfrom
fix/login-unhandled-rejection

Conversation

@cuzzlor

@cuzzlor cuzzlor commented Aug 15, 2026 •

Copy link
Copy Markdown
Collaborator

Stack 2/3 — stacked on #17 (base branch chore/npm-audit); the diff shows only this PR's commit. Merge #17 first, then this, then #16. The version bump for the release ships at the top of the stack in #16.

Problem

createLoginHandler's promise chain ends in a terminal .catch((error) => { throw error }). Rethrowing inside a terminal catch converts the error into an unhandled promise rejection, which terminates the Node process (default behaviour since Node 15).

Any failure while initiating an interactive login — e.g. a transient Entra metadata fetch error inside msalClient.getAuthCodeUrl, or a throwing authorizationUrlRequestOverride — is reachable by an anonymous GET with accept: text/html, so a single request during an Entra blip takes the whole server down.

Fix

Log the error via the configured logger and respond 500, matching createAuthHandler's existing error handling. logger is now threaded through AuthInput to createLoginHandler for this purpose (no public API change — AuthConfig already has logger).

Testing

Added src/login-handler.spec.ts (first tests in the repo — vitest was already wired up):

  • login initiation failure responds 500 (under the old code this test run dies on the unhandled rejection)
  • successful initiation still redirects to the auth code URL

npm run lint, npm run check-types, and npm test all pass.

🤖 Generated with Claude Code

@cuzzlor

cuzzlor commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator Author

CI here fails only on the audit step — advisories pre-dating this branch (main fails identically). #17 clears them; update this branch after it merges and CI should go green.

createLoginHandler's promise chain ended in a terminal
`.catch((error) => { throw error })` — rethrowing inside a terminal
catch produces an unhandled promise rejection, which terminates the
Node process. Any failure while initiating an interactive login (e.g.
a transient Entra metadata fetch error inside getAuthCodeUrl) was
reachable by an anonymous GET and took the whole server down.

Log the error via the configured logger and respond 500, matching
createAuthHandler's error handling. The logger is now threaded through
to createLoginHandler for this purpose.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cuzzlor
cuzzlor requested a review from robdmoore August 15, 2026 09:42
@cuzzlor
cuzzlor force-pushed the fix/login-unhandled-rejection branch from b139384 to 437ffd3 Compare August 15, 2026 09:43
@cuzzlor
cuzzlor changed the base branch from main to chore/npm-audit August 15, 2026 09:43
@cuzzlor
cuzzlor merged commit fe5645f into main Aug 16, 2026
1 check passed
cuzzlor added a commit that referenced this pull request Aug 16, 2026
`npm audit fix` resolves 23 of the 24 advisories accumulated since the
last release (vite, shell-quote, qs, fast-uri, launch-editor, etc. —
all transitive devDependencies; nothing shipped changes).

The remaining low-severity advisory (GHSA-g7r4-m6w7-qqqr, esbuild
0.27.3–0.28.0 dev-server file read on Windows) has no in-range fix via
tsx/vite yet, so it gets an .nsprc exception with removal notes —
esbuild is only used here as a build/test transform, never as a dev
server. The stale uuid exception (fixed by the update) is removed.

Unblocks CI for #15 and #16, which fail on the audit step for
advisories predating those branches.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants