feat: images upload

This commit is contained in:
Ivan Rezchikov
2026-07-04 15:45:05 +03:00
parent 2eb0de5357
commit e192717466
38 changed files with 1334 additions and 615 deletions
+29
View File
@@ -0,0 +1,29 @@
import { unstable_rethrow } from "next/navigation";
import { Prisma } from "@/lib/generated/prisma/client";
import { AppError, type ActionResult } from "./action-result";
export function isPrismaError(error: unknown, code: string): boolean {
return error instanceof Prisma.PrismaClientKnownRequestError && error.code === code;
}
export async function runAction<T>(fn: () => Promise<T>): Promise<ActionResult<T>> {
try {
const data = await fn();
return { success: true, data };
} catch (e) {
unstable_rethrow(e);
if (e instanceof AppError) {
return { success: false, error: e.message, fieldErrors: e.fieldErrors };
}
if (isPrismaError(e, "P2025")) {
return { success: false, error: "This record was updated by someone else. Please refresh and try again." };
}
if (isPrismaError(e, "P2002")) {
return { success: false, error: "This record already exists." };
}
console.error(e);
return { success: false, error: "Something went wrong. Please try again." };
}
}