Skip to content

Commit 9b4f7e9

Browse files
committed
feat: added error handler on creating users that it could not fetch the contact for jid
1 parent b8154ec commit 9b4f7e9

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

src/components/services/user.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,28 @@ export async function findOrCreateUser(msg: Message): Promise<boolean> {
2323
return false;
2424
}
2525

26-
const contact = await msg.getContact();
27-
const countryCode = await contact.getCountryCode();
28-
const about = await contact.getAbout();
29-
const name = contact.pushname || contact.name || "Unknown";
26+
try {
27+
const contact = await msg.getContact();
28+
const countryCode = await contact.getCountryCode();
29+
const about = await contact.getAbout();
30+
const name = contact.pushname || contact.name || "Unknown";
3031

31-
user = await prisma.user.create({
32-
data: {
33-
lid,
34-
name,
35-
number: contact.number,
36-
countryCode,
37-
type: contact.isBusiness ? "business" : "private",
38-
mode: msg.author ? "group" : "private",
39-
about: about,
40-
commandCount: 1,
41-
},
42-
});
32+
user = await prisma.user.create({
33+
data: {
34+
lid,
35+
name,
36+
number: contact.number,
37+
countryCode,
38+
type: contact.isBusiness ? "business" : "private",
39+
mode: msg.author ? "group" : "private",
40+
about: about,
41+
commandCount: 1,
42+
},
43+
});
44+
} catch (err) {
45+
log.error("Database", `Could not fetch contact for JID: ${jid}`);
46+
return false;
47+
}
4348
} catch (error) {
4449
log.error("Database", `Failed to find or create user.`, error);
4550
}
@@ -121,4 +126,4 @@ export async function getUsers(): Promise<any[]> {
121126
log.error("Database", `Failed to get users.`, error);
122127
return [];
123128
}
124-
}
129+
}

0 commit comments

Comments
 (0)