Skip to content

Commit

Permalink
エラーメッセージ強化
Browse files Browse the repository at this point in the history
  • Loading branch information
tegnike committed Aug 30, 2024
1 parent b33b542 commit ef27e02
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
16 changes: 12 additions & 4 deletions src/features/chat/vercelAIChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ export async function getVercelAIChatResponse(
})

if (!response.ok) {
throw new Error(`API request to ${aiService} failed`)
throw new Error(
`API request to ${aiService} failed with status ${response.status} and body ${await response.text()}`
)
}

if (!response.body) {
throw new Error(`API response from ${aiService} is empty`)
throw new Error(
`API response from ${aiService} is empty, status ${response.status}`
)
}

const data = await response.json()
Expand Down Expand Up @@ -58,13 +62,17 @@ export async function getVercelAIChatResponseStream(
})

if (!response.ok) {
throw new Error(`API request to ${aiService} failed`)
throw new Error(
`API request to ${aiService} failed with status ${response.status} and body ${await response.text()}`
)
}

return new ReadableStream({
async start(controller) {
if (!response.body) {
throw new Error(`API response from ${aiService} is empty`)
throw new Error(
`API response from ${aiService} is empty, status ${response.status}`
)
}

const reader = response.body.getReader()
Expand Down
4 changes: 3 additions & 1 deletion src/features/slide/slideAIHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export const judgeSlide = async (
const apiKey = ss[apiKeyName]

if (!apiKey) {
throw new Error('API key not found')
throw new Error(
`API key for ${aiService} is missing. Unable to proceed with the AI service.`
)
}

const systemMessage = `
Expand Down
4 changes: 3 additions & 1 deletion src/features/youtube/conversationContinuityFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const getAIConfig = () => {
const apiKey = ss[apiKeyName]

if (!apiKey) {
throw new Error('API key not found')
throw new Error(
`API key for ${aiService} is missing. Unable to proceed with the AI service.`
)
}

return {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/aiChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default async function handler(req: NextRequest) {
model: instance(model),
messages: modifiedMessages,
})
debugger

return result
}
}
Expand Down

0 comments on commit ef27e02

Please sign in to comment.