fix(auth/swagger): make WA failure non-fatal and include /api prefix in docs

This commit is contained in:
2026-04-01 17:04:25 +08:00
parent a3940321a7
commit b751f031cd
5 changed files with 182 additions and 172 deletions

View File

@@ -17,18 +17,22 @@ export async function POST(req: Request) {
const codeOtp = randomOTP();
const otpNumber = Number(codeOtp);
console.log(`🔑 DEBUG RESEND OTP [${nomor}]: ${codeOtp}`);
// Kirim OTP via WhatsApp
const waMessage = `Website Desa Darmasaba - Kode ini bersifat RAHASIA dan JANGAN DI BAGIKAN KEPADA SIAPAPUN, termasuk anggota ataupun Admin lainnya.\n\n>> Kode OTP anda: ${codeOtp}.`;
const waUrl = `https://wa.wibudev.com/code?nom=${encodeURIComponent(nomor)}&text=${encodeURIComponent(waMessage)}`;
const waRes = await fetch(waUrl);
const waData = await waRes.json();
if (waData.status !== "success") {
return NextResponse.json(
{ success: false, message: "Gagal mengirim OTP via WhatsApp" },
{ status: 400 }
);
try {
const waRes = await fetch(waUrl);
if (!waRes.ok) {
console.warn(`⚠️ WA Service HTTP Error (Resend): ${waRes.status} ${waRes.statusText}. Continuing since OTP is logged.`);
} else {
const waData = await waRes.json();
console.log("📱 WA Response (Resend):", waData);
}
} catch (waError: any) {
console.warn("⚠️ WA Connection Exception (Resend). Continuing since OTP is logged.", waError.message);
}
// Simpan OTP ke database