mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 12:49:32 +00:00
improvement: error handling on contact creation
This commit is contained in:
@@ -92,7 +92,9 @@ export const getWbot = (whatsappId: number): Session => {
|
|||||||
const sessionIndex = sessions.findIndex(s => s.id === whatsappId);
|
const sessionIndex = sessions.findIndex(s => s.id === whatsappId);
|
||||||
|
|
||||||
if (sessionIndex === -1) {
|
if (sessionIndex === -1) {
|
||||||
throw new AppError("This WhatsApp session is not initialized.");
|
throw new AppError(
|
||||||
|
"This WhatsApp session is not initialized. Check connections page."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return sessions[sessionIndex];
|
return sessions[sessionIndex];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ const CreateContactService = async ({
|
|||||||
throw new AppError("A contact with this number already exists.");
|
throw new AppError("A contact with this number already exists.");
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("extra", extraInfo);
|
|
||||||
|
|
||||||
const contact = await Contact.create(
|
const contact = await Contact.create(
|
||||||
{
|
{
|
||||||
name,
|
name,
|
||||||
|
|||||||
@@ -10,10 +10,13 @@ const CheckIsValidContact = async (number: string): Promise<void> => {
|
|||||||
try {
|
try {
|
||||||
const isValidNumber = await wbot.isRegisteredUser(`${number}@c.us`);
|
const isValidNumber = await wbot.isRegisteredUser(`${number}@c.us`);
|
||||||
if (!isValidNumber) {
|
if (!isValidNumber) {
|
||||||
throw new AppError("The suplied number is not a valid Whatsapp number");
|
throw new AppError("invalidNumber");
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
if (err.message === "invalidNumber") {
|
||||||
|
throw new AppError("This is not a valid whatsapp number.");
|
||||||
|
}
|
||||||
throw new AppError(
|
throw new AppError(
|
||||||
"Could not valid WhatsApp contact. Check connections page"
|
"Could not valid WhatsApp contact. Check connections page"
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user