fix(auth/swagger): make WA failure non-fatal and include /api prefix in docs
This commit is contained in:
@@ -33,6 +33,8 @@ export async function POST(req: Request) {
|
||||
const codeOtp = randomOTP();
|
||||
const otpNumber = Number(codeOtp);
|
||||
|
||||
console.log(`🔑 DEBUG OTP [${nomor}]: ${codeOtp}`);
|
||||
|
||||
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)}`;
|
||||
|
||||
@@ -40,26 +42,19 @@ export async function POST(req: Request) {
|
||||
|
||||
try {
|
||||
const res = await fetch(waUrl);
|
||||
const sendWa = await res.json();
|
||||
console.log("📱 WA Response:", sendWa);
|
||||
|
||||
if (sendWa.status !== "success") {
|
||||
console.error("❌ WA Service Error:", sendWa);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Gagal mengirim OTP via WhatsApp",
|
||||
debug: sendWa
|
||||
},
|
||||
{ status: 400 }
|
||||
);
|
||||
if (!res.ok) {
|
||||
const errorText = await res.text();
|
||||
console.error(`⚠️ WA Service HTTP Error: ${res.status} ${res.statusText}. Continuing since OTP is logged.`);
|
||||
console.log(`💡 Use this OTP to login: ${codeOtp}`);
|
||||
} else {
|
||||
const sendWa = await res.json();
|
||||
console.log("📱 WA Response:", sendWa);
|
||||
if (sendWa.status !== "success") {
|
||||
console.error("⚠️ WA Service Logic Error:", sendWa);
|
||||
}
|
||||
}
|
||||
} catch (waError) {
|
||||
console.error("❌ Fetch WA Error:", waError);
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Terjadi kesalahan saat mengirim WA" },
|
||||
{ status: 500 }
|
||||
);
|
||||
} catch (waError: any) {
|
||||
console.error("⚠️ WA Connection Exception. Continuing since OTP is logged.", waError.message);
|
||||
}
|
||||
|
||||
const createOtpId = await prisma.kodeOtp.create({
|
||||
|
||||
@@ -22,14 +22,21 @@ export async function POST(req: Request) {
|
||||
// ✅ Generate dan kirim OTP
|
||||
const codeOtp = randomOTP();
|
||||
const otpNumber = Number(codeOtp);
|
||||
console.log(`🔑 DEBUG REGISTER OTP [${nomor}]: ${codeOtp}`);
|
||||
|
||||
const waMessage = `Website Desa Darmasaba - Kode verifikasi 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 (Register): ${waRes.status} ${waRes.statusText}. Continuing since OTP is logged.`);
|
||||
} else {
|
||||
const waData = await waRes.json();
|
||||
console.log("📱 WA Response (Register):", waData);
|
||||
}
|
||||
} catch (waError: any) {
|
||||
console.warn("⚠️ WA Connection Exception (Register). Continuing since OTP is logged.", waError.message);
|
||||
}
|
||||
|
||||
// ✅ Simpan OTP ke database
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -21,14 +21,21 @@ export async function POST(req: Request) {
|
||||
// Generate OTP
|
||||
const codeOtp = randomOTP();
|
||||
const otpNumber = Number(codeOtp);
|
||||
console.log(`🔑 DEBUG SEND-OTP-REGISTER [${nomor}]: ${codeOtp}`);
|
||||
|
||||
// Kirim WA
|
||||
const waUrl = `https://wa.wibudev.com/code?nom=${encodeURIComponent(nomor)}&text=Website Desa Darmasaba - Kode verifikasi Anda: ${codeOtp}`;
|
||||
const res = await fetch(waUrl);
|
||||
const sendWa = await res.json();
|
||||
|
||||
if (sendWa.status !== "success") {
|
||||
return NextResponse.json({ success: false, message: 'Gagal mengirim OTP' }, { status: 400 });
|
||||
|
||||
try {
|
||||
const res = await fetch(waUrl);
|
||||
if (!res.ok) {
|
||||
console.warn(`⚠️ WA Service HTTP Error (SendOTPRegister): ${res.status} ${res.statusText}. Continuing since OTP is logged.`);
|
||||
} else {
|
||||
const sendWa = await res.json();
|
||||
console.log("📱 WA Response (SendOTPRegister):", sendWa);
|
||||
}
|
||||
} catch (waError: any) {
|
||||
console.warn("⚠️ WA Connection Exception (SendOTPRegister). Continuing since OTP is logged.", waError.message);
|
||||
}
|
||||
|
||||
// Simpan OTP
|
||||
|
||||
Reference in New Issue
Block a user