Return 500 when OPENAI_API_KEY is missing in auth middleware - #1
Open
heliosran wants to merge 1 commit into
Open
Return 500 when OPENAI_API_KEY is missing in auth middleware#1heliosran wants to merge 1 commit into
heliosran wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
OPENAI_API_KEYis not set.{ error: { message: ... } }and avoid accidental fall-through to downstream handlers.Description
openaiAuthMiddleware()so theif (!configuredKey)branch immediately returnsc.json({ error: { message: "Server configuration error" } }, 500)instead of callingnext().test/index.spec.tsthat cover missingAuthorization(401), invalid bearer format (401), missingOPENAI_API_KEY(500), and valid key allowing the request (200).Testing
npx vitest run test/index.spec.ts --config vitest.local.config.mtsand all middleware tests passed (4 passed).npm run tscwhich succeeded with no type errors.npm run lintwhich completed successfully.npm testpath in this environment fails due to a missingwrangler.jsoncfile, so the focused middleware tests were run with a temporary Vitest config instead.Codex Task