Skip to content

Return 500 when OPENAI_API_KEY is missing in auth middleware - #1

Open
heliosran wants to merge 1 commit into
mainfrom
codex/update-openaiauthmiddleware-for-error-handling
Open

Return 500 when OPENAI_API_KEY is missing in auth middleware#1
heliosran wants to merge 1 commit into
mainfrom
codex/update-openaiauthmiddleware-for-error-handling

Conversation

@heliosran

Copy link
Copy Markdown
Owner

Motivation

  • Ensure the authentication middleware stops processing and surfaces a server-side configuration error when OPENAI_API_KEY is not set.
  • Keep the existing error envelope shape { error: { message: ... } } and avoid accidental fall-through to downstream handlers.

Description

  • Updated openaiAuthMiddleware() so the if (!configuredKey) branch immediately returns c.json({ error: { message: "Server configuration error" } }, 500) instead of calling next().
  • Ensured there is no fall-through in that branch by returning early.
  • Replaced the placeholder worker tests with focused middleware tests in test/index.spec.ts that cover missing Authorization (401), invalid bearer format (401), missing OPENAI_API_KEY (500), and valid key allowing the request (200).

Testing

  • Ran npx vitest run test/index.spec.ts --config vitest.local.config.mts and all middleware tests passed (4 passed).
  • Ran npm run tsc which succeeded with no type errors.
  • Ran npm run lint which completed successfully.
  • Note: the default npm test path in this environment fails due to a missing wrangler.jsonc file, so the focused middleware tests were run with a temporary Vitest config instead.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant