fix
This commit is contained in:
@@ -13,7 +13,18 @@ async function callEdgeFunction(content: string): Promise<WritingFeedback> {
|
||||
body: { content },
|
||||
})
|
||||
|
||||
if (error) throw new Error(error.message ?? "Đã có lỗi khi chấm bài. Vui lòng thử lại.")
|
||||
if (error) {
|
||||
// The Supabase SDK wraps non-2xx responses in a generic FunctionsHttpError.
|
||||
// Try to parse the actual error body returned by the edge function.
|
||||
try {
|
||||
const body = await (error as unknown as { context: Response }).context.json()
|
||||
if (body?.error) throw new Error(body.error)
|
||||
} catch {
|
||||
// ignore parse failure, fall through to generic message
|
||||
}
|
||||
throw new Error("Đã có lỗi khi chấm bài. Vui lòng thử lại.")
|
||||
}
|
||||
|
||||
if (!data) throw new Error("Phản hồi từ AI không hợp lệ. Vui lòng thử lại.")
|
||||
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user