Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Chore/fix error handling in generate v3 (#30913)

Joshen Lim7ca43d891989
diff --git a/apps/studio/pages/api/ai/sql/generate-v3.ts b/apps/studio/pages/api/ai/sql/generate-v3.ts
index 55517ba1c0b..4218aa062d6 100644
--- a/apps/studio/pages/api/ai/sql/generate-v3.ts
+++ b/apps/studio/pages/api/ai/sql/generate-v3.ts
@@ -1,25 +1,20 @@
import { openai } from '@ai-sdk/openai'
-import { streamText } from 'ai'
-import { getTools } from './tools'
import pgMeta from '@supabase/pg-meta'
-import { executeSql } from 'data/sql/execute-sql-query'
+import { streamText } from 'ai'
import { NextApiRequest, NextApiResponse } from 'next'
+import { executeSql } from 'data/sql/execute-sql-query'
+import { getTools } from './tools'
+
export const maxDuration = 30
const openAiKey = process.env.OPENAI_API_KEY
const pgMetaSchemasList = pgMeta.schemas.list()
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!openAiKey) {
- return new Response(
- JSON.stringify({
- error: 'No OPENAI_API_KEY set. Create this environment variable to use AI features.',
- }),
- {
- status: 500,
- headers: { 'Content-Type': 'application/json' },
- }
- )
+ return res.status(400).json({
+ error: 'No OPENAI_API_KEY set. Create this environment variable to use AI features.',
+ })
}
const { method } = req
@@ -28,13 +23,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
case 'POST':
return handlePost(req, res)
default:
- return new Response(
- JSON.stringify({ data: null, error: { message: `Method ${method} Not Allowed` } }),
- {
- status: 405,
- headers: { 'Content-Type': 'application/json', Allow: 'POST' },
- }
- )
+ res.setHeader('Allow', ['POST'])
+ res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } })
}
}