Skip to content
Snippets Groups Projects
Unverified Commit 3bb94da8 authored by Thuc Pham's avatar Thuc Pham Committed by GitHub
Browse files

feat: show alert when getting chat error (#55)

parent 418bf9ba
Branches
Tags
No related merge requests found
import os import os
from app.engine.index import get_index from app.engine.index import get_index
from fastapi import HTTPException
def get_chat_engine(): def get_chat_engine():
...@@ -8,8 +9,11 @@ def get_chat_engine(): ...@@ -8,8 +9,11 @@ def get_chat_engine():
index = get_index() index = get_index()
if index is None: if index is None:
raise Exception( raise HTTPException(
"StorageContext is empty - call 'poetry run generate' to generate the storage first" status_code=500,
detail=str(
"StorageContext is empty - call 'poetry run generate' to generate the storage first"
),
) )
return index.as_chat_engine( return index.as_chat_engine(
......
...@@ -57,7 +57,7 @@ export const chatRequest = async (req: Request, res: Response) => { ...@@ -57,7 +57,7 @@ export const chatRequest = async (req: Request, res: Response) => {
} catch (error) { } catch (error) {
console.error("[LlamaIndex]", error); console.error("[LlamaIndex]", error);
return res.status(500).json({ return res.status(500).json({
error: (error as Error).message, detail: (error as Error).message,
}); });
} }
}; };
...@@ -71,7 +71,7 @@ export const chat = async (req: Request, res: Response) => { ...@@ -71,7 +71,7 @@ export const chat = async (req: Request, res: Response) => {
} catch (error) { } catch (error) {
console.error("[LlamaIndex]", error); console.error("[LlamaIndex]", error);
return res.status(500).json({ return res.status(500).json({
error: (error as Error).message, detail: (error as Error).message,
}); });
} }
}; };
...@@ -74,7 +74,7 @@ export async function POST(request: NextRequest) { ...@@ -74,7 +74,7 @@ export async function POST(request: NextRequest) {
console.error("[LlamaIndex]", error); console.error("[LlamaIndex]", error);
return NextResponse.json( return NextResponse.json(
{ {
error: (error as Error).message, detail: (error as Error).message,
}, },
{ {
status: 500, status: 500,
......
...@@ -17,6 +17,10 @@ export default function ChatSection() { ...@@ -17,6 +17,10 @@ export default function ChatSection() {
headers: { headers: {
"Content-Type": "application/json", // using JSON because of vercel/ai 2.2.26 "Content-Type": "application/json", // using JSON because of vercel/ai 2.2.26
}, },
onError: (error) => {
const message = JSON.parse(error.message);
alert(message.detail);
},
}); });
return ( return (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment