fix: decouple AI completion from history save failures and improve history API errors
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,21 +1,32 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getHistoryUsername } from "@/lib/history/request-user";
|
||||
import { deleteHistoryEntry } from "@/lib/history/server-store";
|
||||
import {
|
||||
deleteHistoryEntry,
|
||||
historyStoreErrorMessage,
|
||||
} from "@/lib/history/server-store";
|
||||
|
||||
export async function DELETE(
|
||||
_req: Request,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const username = await getHistoryUsername();
|
||||
if (!username) {
|
||||
return NextResponse.json({ error: "请先登录" }, { status: 401 });
|
||||
}
|
||||
try {
|
||||
const username = await getHistoryUsername();
|
||||
if (!username) {
|
||||
return NextResponse.json({ error: "请先登录" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
const removed = await deleteHistoryEntry(username, id);
|
||||
if (!removed) {
|
||||
return NextResponse.json({ error: "记录不存在" }, { status: 404 });
|
||||
}
|
||||
const { id } = await params;
|
||||
const removed = await deleteHistoryEntry(username, id);
|
||||
if (!removed) {
|
||||
return NextResponse.json({ error: "记录不存在" }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ ok: true });
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("[history DELETE]", err);
|
||||
return NextResponse.json(
|
||||
{ error: historyStoreErrorMessage(err) },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user