Skip to content

Commit ca2c986

Browse files
authored
Python template: Adds error message when env var missing (#1272)
### Description Adds a helpful error message when env var is not set ### Demo URL ### Type of Change - [ ] New Example - [x] Example updates (Bug fixes, new features, etc.) - [ ] Other (changes to the codebase, but not to examples) ### New Example Checklist - [ ] 🛫 `npm run new-example` was used to create the example - [ ] 📚 The template wasn't used but I carefuly read the [Adding a new example](https://github.com/vercel/examples#adding-a-new-example) steps and implemented them in the example - [ ] 📱 Is it responsive? Are mobile and tablets considered?
1 parent 08f7f36 commit ca2c986

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

python/vibe-coding-ide/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ npm i
3131
npm run dev
3232
```
3333

34-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the backend.
34+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the frontend.

python/vibe-coding-ide/frontend/src/hooks/useChat.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { API_BASE } from '../constants'
55
import { useProjects } from '../context/ProjectsContext'
66
import { computeProjectHashes } from '../lib/hash'
77

8+
declare const process: { env: Record<string, string | undefined> }
9+
810
interface UseChatProps {
911
userId: string
1012
input: string
@@ -44,6 +46,22 @@ export const useChat = ({
4446
useProjects()
4547
const sendPrompt = useCallback(async () => {
4648
if (!input.trim()) return
49+
// In production, require NEXT_PUBLIC_API_URL to be set; otherwise show a user-facing error
50+
const isProd = (process.env.NODE_ENV || '').trim() === 'production'
51+
const hasApiUrl = Boolean((process.env.NEXT_PUBLIC_API_URL || '').trim())
52+
if (isProd && !hasApiUrl) {
53+
const errorRunId = `config_error_${Date.now()}`
54+
createRun(errorRunId, input, projectId, threadId)
55+
addAction(errorRunId, {
56+
id: `notice_${Date.now()}`,
57+
kind: 'system_notice',
58+
status: 'done',
59+
message:
60+
'Missing environment variable: NEXT_PUBLIC_API_URL is not set. Set it to your backend URL and reload.',
61+
timestamp: new Date().toISOString(),
62+
} as Action)
63+
return
64+
}
4765
setLoading(true)
4866
setInput('')
4967

0 commit comments

Comments
 (0)