fix: Implementasi retry mechanism dan error handling untuk database connections Deskripsi: Menambahkan withRetry wrapper pada berbagai API routes untuk menangani transient database errors dan meningkatkan reliabilitas koneksi Memperbaiki error handling pada notification, authentication, dan user validation endpoints dengan response 503 untuk database connection errors Update prisma.ts dengan konfigurasi logging yang lebih baik dan datasources configuration Menambahkan validasi input parameters pada beberapa endpoints Update dokumentasi QWEN.md dengan commit message format dan comment standards Update .env.example dengan connection pool settings yang lebih lengkap File yang diubah: src/lib/prisma.ts — Konfigurasi Prisma client & logging src/app/api/admin/notifikasi/count/route.tsx src/app/api/auth/mobile-login/route.ts src/app/api/mobile/notification/[id]/route.ts src/app/api/user-validate/route.ts Dan 27 file API routes lainnya (penerapan withRetry secara konsisten) QWEN.md — Dokumentasi commit & comment standards .env.example — Database connection pool configuration ### No Issue
69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
import { prisma } from "@/lib";
|
|
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
|
|
import backendLogger from "@/util/backendLogger";
|
|
import { NextResponse } from "next/server";
|
|
import { funSendToWhatsApp } from "@/lib/code-otp-sender";
|
|
|
|
export async function POST(req: Request) {
|
|
if (req.method !== "POST") {
|
|
return NextResponse.json(
|
|
{ success: false, message: "Method Not Allowed" },
|
|
{ status: 405 },
|
|
);
|
|
}
|
|
|
|
try {
|
|
const codeOtp = randomOTP();
|
|
const body = await req.json();
|
|
const { nomor } = body;
|
|
|
|
const resSendCode = await funSendToWhatsApp({
|
|
nomor,
|
|
codeOtp: codeOtp.toString(),
|
|
});
|
|
|
|
if (resSendCode.status !== 200)
|
|
return NextResponse.json(
|
|
{ success: false, message: "Nomor Whatsapp Tidak Aktif" },
|
|
{ status: 400 },
|
|
);
|
|
|
|
const sendWa = await resSendCode.text();
|
|
console.log("WA Response:", sendWa);
|
|
|
|
const createOtpId = await prisma.kodeOtp.create({
|
|
data: {
|
|
nomor: nomor,
|
|
otp: codeOtp,
|
|
},
|
|
});
|
|
|
|
if (!createOtpId)
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: "Gagal Membuat Kode OTP",
|
|
},
|
|
{ status: 400 },
|
|
);
|
|
|
|
return NextResponse.json(
|
|
{
|
|
success: true,
|
|
message: "Kode Verifikasi Dikirim",
|
|
kodeId: createOtpId.id,
|
|
},
|
|
{ status: 200 },
|
|
);
|
|
} catch (error) {
|
|
backendLogger.error(" Error Resend OTP", error);
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
message: "Server Whatsapp Error !!",
|
|
},
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|