harden database interactions and improve error handling
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
export default defineNitroPlugin(() => {
|
||||
const config = useRuntimeConfig();
|
||||
const missing: string[] = [];
|
||||
|
||||
if (!config.openrouterApiKey) missing.push("NUXT_OPENROUTER_API_KEY");
|
||||
|
||||
const provider = (config.ttsProvider as string || "elevenlabs").toLowerCase();
|
||||
if (provider === "fishaudio") {
|
||||
if (!config.fishAudioApiKey) missing.push("NUXT_FISH_AUDIO_API_KEY");
|
||||
} else {
|
||||
if (!config.elevenlabsApiKey) missing.push("NUXT_ELEVENLABS_API_KEY");
|
||||
}
|
||||
|
||||
if (missing.length > 0) {
|
||||
console.error("[revisione] Missing required env vars:", missing.join(", "));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log("[revisione] env validation passed");
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
export default defineNitroPlugin((nitro) => {
|
||||
nitro.hooks.hook("error", async (error, { event }) => {
|
||||
// only log server-side, never expose internals to client
|
||||
const status = (error as any)?.statusCode ?? 500;
|
||||
if (status >= 500) {
|
||||
console.error("[revisione] unhandled error:", error?.message ?? error);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,11 +1,32 @@
|
||||
import { db } from "../db/index";
|
||||
import { courses } from "../db/schema";
|
||||
import { courses, topics, lessons } from "../db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { generateCourseInBackground } from "../utils/generateCourse";
|
||||
|
||||
export default defineNitroPlugin(async () => {
|
||||
console.log("[revisione] resumeGeneration plugin started");
|
||||
|
||||
// reset any stuck generating states from a previous run
|
||||
try {
|
||||
const stuckTopics = await db
|
||||
.update(topics)
|
||||
.set({ status: "pending" })
|
||||
.where(eq(topics.status, "generating"))
|
||||
.returning({ id: topics.id });
|
||||
|
||||
const stuckLessons = await db
|
||||
.update(lessons)
|
||||
.set({ branchStatus: "pending" })
|
||||
.where(eq(lessons.branchStatus, "generating"))
|
||||
.returning({ id: lessons.id });
|
||||
|
||||
if (stuckTopics.length > 0 || stuckLessons.length > 0) {
|
||||
console.log(`[revisione] reset ${stuckTopics.length} stuck topic(s) and ${stuckLessons.length} stuck lesson(s) to pending`);
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error("[revisione] failed to reset stuck states:", err?.message ?? err);
|
||||
}
|
||||
|
||||
try {
|
||||
const stuck = await db.query.courses.findMany({
|
||||
where: eq(courses.status, "processing"),
|
||||
|
||||
Reference in New Issue
Block a user