fix(baileys): corrigir declaração de variável error em blocos catch

This commit is contained in:
OrionDesign
2025-12-11 17:11:58 -03:00
parent 67c4aa640b
commit 2fee5053f3

View File

@@ -733,7 +733,7 @@ export class BaileysStartupService extends ChannelStartupService {
}); });
return await this.createClient(number); return await this.createClient(number);
} catch { } catch (error) {
this.logger.error(error); this.logger.error(error);
throw new InternalServerErrorException(error?.toString()); throw new InternalServerErrorException(error?.toString());
} }
@@ -742,7 +742,7 @@ export class BaileysStartupService extends ChannelStartupService {
public async reloadConnection(): Promise<WASocket> { public async reloadConnection(): Promise<WASocket> {
try { try {
return await this.createClient(this.phoneNumber); return await this.createClient(this.phoneNumber);
} catch { } catch (error) {
this.logger.error(error); this.logger.error(error);
throw new InternalServerErrorException(error?.toString()); throw new InternalServerErrorException(error?.toString());
} }
@@ -888,7 +888,7 @@ export class BaileysStartupService extends ChannelStartupService {
}), }),
); );
} }
} catch { } catch (error) {
console.error(error); console.error(error);
this.logger.error(`Error: ${error.message}`); this.logger.error(`Error: ${error.message}`);
} }
@@ -1074,7 +1074,7 @@ export class BaileysStartupService extends ChannelStartupService {
contacts = undefined; contacts = undefined;
messages = undefined; messages = undefined;
chats = undefined; chats = undefined;
} catch { } catch (error) {
this.logger.error(error); this.logger.error(error);
} }
}, },
@@ -1434,7 +1434,7 @@ export class BaileysStartupService extends ChannelStartupService {
await this.prismaRepository.message.update({ where: { id: msg.id }, data: messageRaw }); await this.prismaRepository.message.update({ where: { id: msg.id }, data: messageRaw });
} }
} catch { } catch (error) {
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]); this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);
} }
} }
@@ -1466,7 +1466,7 @@ export class BaileysStartupService extends ChannelStartupService {
messageRaw.message.base64 = buffer.toString('base64'); messageRaw.message.base64 = buffer.toString('base64');
} }
} }
} catch { } catch (error) {
this.logger.error(['Error converting media to base64', error?.message]); this.logger.error(['Error converting media to base64', error?.message]);
} }
} }
@@ -1550,7 +1550,7 @@ export class BaileysStartupService extends ChannelStartupService {
create: contactRaw, create: contactRaw,
}); });
} }
} catch { } catch (error) {
this.logger.error(error); this.logger.error(error);
} }
}, },
@@ -1798,7 +1798,7 @@ export class BaileysStartupService extends ChannelStartupService {
}; };
this.sendDataWebhook(Events.GROUP_PARTICIPANTS_UPDATE, enhancedParticipantsUpdate); this.sendDataWebhook(Events.GROUP_PARTICIPANTS_UPDATE, enhancedParticipantsUpdate);
} catch { } catch (error) {
this.logger.error( this.logger.error(
`Failed to resolve participant data for GROUP_PARTICIPANTS_UPDATE webhook: ${error.message} | Group: ${participantsUpdate.id} | Participants: ${participantsUpdate.participants.length}`, `Failed to resolve participant data for GROUP_PARTICIPANTS_UPDATE webhook: ${error.message} | Group: ${participantsUpdate.id} | Participants: ${participantsUpdate.participants.length}`,
); );
@@ -2005,7 +2005,7 @@ export class BaileysStartupService extends ChannelStartupService {
return; return;
} }
} }
} catch { } catch (error) {
this.logger.error(error); this.logger.error(error);
} }
}); });
@@ -2122,7 +2122,7 @@ export class BaileysStartupService extends ChannelStartupService {
// return call; // return call;
return { id: '123', jid, isVideo, callDuration }; return { id: '123', jid, isVideo, callDuration };
} catch { } catch (error) {
return error; return error;
} }
} }
@@ -2503,7 +2503,7 @@ export class BaileysStartupService extends ChannelStartupService {
await this.prismaRepository.message.update({ where: { id: msg.id }, data: messageRaw }); await this.prismaRepository.message.update({ where: { id: msg.id }, data: messageRaw });
} }
} catch { } catch (error) {
this.logger.error(['Error on upload file to minio', error?.message, error?.stack]); this.logger.error(['Error on upload file to minio', error?.message, error?.stack]);
} }
} }
@@ -2534,7 +2534,7 @@ export class BaileysStartupService extends ChannelStartupService {
messageRaw.message.base64 = buffer.toString('base64'); messageRaw.message.base64 = buffer.toString('base64');
} }
} }
} catch { } catch (error) {
this.logger.error(['Error converting media to base64', error?.message]); this.logger.error(['Error converting media to base64', error?.message]);
} }
} }
@@ -2555,7 +2555,7 @@ export class BaileysStartupService extends ChannelStartupService {
} }
return messageRaw; return messageRaw;
} catch { } catch (error) {
this.logger.error(error); this.logger.error(error);
throw new BadRequestException(error.toString()); throw new BadRequestException(error.toString());
} }
@@ -2607,7 +2607,7 @@ export class BaileysStartupService extends ChannelStartupService {
} }
return { presence: data.presence }; return { presence: data.presence };
} catch { } catch (error) {
this.logger.error(error); this.logger.error(error);
throw new BadRequestException(error.toString()); throw new BadRequestException(error.toString());
} }
@@ -2619,7 +2619,7 @@ export class BaileysStartupService extends ChannelStartupService {
await this.client.sendPresenceUpdate(data.presence); await this.client.sendPresenceUpdate(data.presence);
return { presence: data.presence }; return { presence: data.presence };
} catch { } catch (error) {
this.logger.error(error); this.logger.error(error);
throw new BadRequestException(error.toString()); throw new BadRequestException(error.toString());
} }
@@ -2860,7 +2860,7 @@ export class BaileysStartupService extends ChannelStartupService {
this.logger.verbose(`Video duration: ${duration} seconds`); this.logger.verbose(`Video duration: ${duration} seconds`);
prepareMedia[mediaType].seconds = duration; prepareMedia[mediaType].seconds = duration;
} catch { } catch (error) {
this.logger.error('Error getting video duration:'); this.logger.error('Error getting video duration:');
this.logger.error(error); this.logger.error(error);
throw new Error(`Failed to get video duration: ${error.message}`); throw new Error(`Failed to get video duration: ${error.message}`);
@@ -2887,7 +2887,7 @@ export class BaileysStartupService extends ChannelStartupService {
{ [mediaType]: { ...prepareMedia[mediaType] } }, { [mediaType]: { ...prepareMedia[mediaType] } },
{ userJid: this.instance.wuid }, { userJid: this.instance.wuid },
); );
} catch { } catch (error) {
this.logger.error(error); this.logger.error(error);
throw new InternalServerErrorException(error?.toString() || error); throw new InternalServerErrorException(error?.toString() || error);
} }
@@ -2932,7 +2932,7 @@ export class BaileysStartupService extends ChannelStartupService {
} else { } else {
return await sharp(imageBuffer).webp().toBuffer(); return await sharp(imageBuffer).webp().toBuffer();
} }
} catch { } catch (error) {
console.error('Erro ao converter a imagem para WebP:', error); console.error('Erro ao converter a imagem para WebP:', error);
throw error; throw error;
} }
@@ -3683,7 +3683,7 @@ export class BaileysStartupService extends ChannelStartupService {
}); });
await this.client.readMessages(keys); await this.client.readMessages(keys);
return { message: 'Read messages', read: 'success' }; return { message: 'Read messages', read: 'success' };
} catch { } catch (error) {
throw new InternalServerErrorException('Read messages fail', error.toString()); throw new InternalServerErrorException('Read messages fail', error.toString());
} }
} }
@@ -3732,7 +3732,7 @@ export class BaileysStartupService extends ChannelStartupService {
await this.client.chatModify({ archive: data.archive, lastMessages: [last_message] }, createJid(number)); await this.client.chatModify({ archive: data.archive, lastMessages: [last_message] }, createJid(number));
return { chatId: number, archived: true }; return { chatId: number, archived: true };
} catch { } catch (error) {
throw new InternalServerErrorException({ throw new InternalServerErrorException({
archived: false, archived: false,
message: ['An error occurred while archiving the chat. Open a calling.', error.toString()], message: ['An error occurred while archiving the chat. Open a calling.', error.toString()],
@@ -3760,7 +3760,7 @@ export class BaileysStartupService extends ChannelStartupService {
await this.client.chatModify({ markRead: false, lastMessages: [last_message] }, createJid(number)); await this.client.chatModify({ markRead: false, lastMessages: [last_message] }, createJid(number));
return { chatId: number, markedChatUnread: true }; return { chatId: number, markedChatUnread: true };
} catch { } catch (error) {
throw new InternalServerErrorException({ throw new InternalServerErrorException({
markedChatUnread: false, markedChatUnread: false,
message: ['An error occurred while marked unread the chat. Open a calling.', error.toString()], message: ['An error occurred while marked unread the chat. Open a calling.', error.toString()],
@@ -3817,7 +3817,7 @@ export class BaileysStartupService extends ChannelStartupService {
} }
return response; return response;
} catch { } catch (error) {
throw new InternalServerErrorException('Error while deleting message for everyone', error?.toString()); throw new InternalServerErrorException('Error while deleting message for everyone', error?.toString());
} }
} }
@@ -3955,7 +3955,7 @@ export class BaileysStartupService extends ChannelStartupService {
return result; return result;
} }
} catch { } catch (error) {
this.logger.error('Error converting audio to mp4:'); this.logger.error('Error converting audio to mp4:');
this.logger.error(error); this.logger.error(error);
throw new BadRequestException('Failed to convert audio to MP4'); throw new BadRequestException('Failed to convert audio to MP4');
@@ -3971,7 +3971,7 @@ export class BaileysStartupService extends ChannelStartupService {
base64: buffer.toString('base64'), base64: buffer.toString('base64'),
buffer: getBuffer ? buffer : null, buffer: getBuffer ? buffer : null,
}; };
} catch { } catch (error) {
this.logger.error('Error processing media message:'); this.logger.error('Error processing media message:');
this.logger.error(error); this.logger.error(error);
throw new BadRequestException(error.toString()); throw new BadRequestException(error.toString());
@@ -4013,7 +4013,7 @@ export class BaileysStartupService extends ChannelStartupService {
groupadd: settings.groupadd, groupadd: settings.groupadd,
}, },
}; };
} catch { } catch (error) {
throw new InternalServerErrorException('Error updating privacy settings', error.toString()); throw new InternalServerErrorException('Error updating privacy settings', error.toString());
} }
} }
@@ -4031,7 +4031,7 @@ export class BaileysStartupService extends ChannelStartupService {
} }
return { isBusiness: true, ...profile }; return { isBusiness: true, ...profile };
} catch { } catch (error) {
throw new InternalServerErrorException('Error updating profile name', error.toString()); throw new InternalServerErrorException('Error updating profile name', error.toString());
} }
} }
@@ -4041,7 +4041,7 @@ export class BaileysStartupService extends ChannelStartupService {
await this.client.updateProfileName(name); await this.client.updateProfileName(name);
return { update: 'success' }; return { update: 'success' };
} catch { } catch (error) {
throw new InternalServerErrorException('Error updating profile name', error.toString()); throw new InternalServerErrorException('Error updating profile name', error.toString());
} }
} }
@@ -4051,7 +4051,7 @@ export class BaileysStartupService extends ChannelStartupService {
await this.client.updateProfileStatus(status); await this.client.updateProfileStatus(status);
return { update: 'success' }; return { update: 'success' };
} catch { } catch (error) {
throw new InternalServerErrorException('Error updating profile status', error.toString()); throw new InternalServerErrorException('Error updating profile status', error.toString());
} }
} }
@@ -4092,7 +4092,7 @@ export class BaileysStartupService extends ChannelStartupService {
this.reloadConnection(); this.reloadConnection();
return { update: 'success' }; return { update: 'success' };
} catch { } catch (error) {
throw new InternalServerErrorException('Error updating profile picture', error.toString()); throw new InternalServerErrorException('Error updating profile picture', error.toString());
} }
} }
@@ -4104,7 +4104,7 @@ export class BaileysStartupService extends ChannelStartupService {
this.reloadConnection(); this.reloadConnection();
return { update: 'success' }; return { update: 'success' };
} catch { } catch (error) {
throw new InternalServerErrorException('Error removing profile picture', error.toString()); throw new InternalServerErrorException('Error removing profile picture', error.toString());
} }
} }
@@ -4124,7 +4124,7 @@ export class BaileysStartupService extends ChannelStartupService {
await this.client.updateBlockStatus(sender, data.status); await this.client.updateBlockStatus(sender, data.status);
return { block: 'success' }; return { block: 'success' };
} catch { } catch (error) {
throw new InternalServerErrorException('Error blocking user', error.toString()); throw new InternalServerErrorException('Error blocking user', error.toString());
} }
} }
@@ -4150,7 +4150,7 @@ export class BaileysStartupService extends ChannelStartupService {
} }
return null; return null;
} catch { } catch (error) {
this.logger.error(error); this.logger.error(error);
throw new BadRequestException(error.toString()); throw new BadRequestException(error.toString());
} }
@@ -4238,7 +4238,7 @@ export class BaileysStartupService extends ChannelStartupService {
} }
return messageSent; return messageSent;
} catch { } catch (error) {
this.logger.error(error); this.logger.error(error);
throw error; throw error;
} }
@@ -4278,7 +4278,7 @@ export class BaileysStartupService extends ChannelStartupService {
return { numberJid: contact.jid, labelId: data.labelId, remove: true }; return { numberJid: contact.jid, labelId: data.labelId, remove: true };
} }
} catch { } catch (error) {
throw new BadRequestException(`Unable to ${data.action} label to chat`, error.toString()); throw new BadRequestException(`Unable to ${data.action} label to chat`, error.toString());
} }
} }
@@ -4296,7 +4296,7 @@ export class BaileysStartupService extends ChannelStartupService {
} }
return meta; return meta;
} catch { } catch (error) {
this.logger.error(error); this.logger.error(error);
return null; return null;
} }
@@ -4344,7 +4344,7 @@ export class BaileysStartupService extends ChannelStartupService {
const group = await this.client.groupMetadata(id); const group = await this.client.groupMetadata(id);
return group; return group;
} catch { } catch (error) {
this.logger.error(error); this.logger.error(error);
throw new InternalServerErrorException('Error creating group', error.toString()); throw new InternalServerErrorException('Error creating group', error.toString());
} }
@@ -4383,7 +4383,7 @@ export class BaileysStartupService extends ChannelStartupService {
await this.client.updateProfilePicture(picture.groupJid, pic); await this.client.updateProfilePicture(picture.groupJid, pic);
return { update: 'success' }; return { update: 'success' };
} catch { } catch (error) {
throw new InternalServerErrorException('Error update group picture', error.toString()); throw new InternalServerErrorException('Error update group picture', error.toString());
} }
} }
@@ -4393,7 +4393,7 @@ export class BaileysStartupService extends ChannelStartupService {
await this.client.groupUpdateSubject(data.groupJid, data.subject); await this.client.groupUpdateSubject(data.groupJid, data.subject);
return { update: 'success' }; return { update: 'success' };
} catch { } catch (error) {
throw new InternalServerErrorException('Error updating group subject', error.toString()); throw new InternalServerErrorException('Error updating group subject', error.toString());
} }
} }
@@ -4403,7 +4403,7 @@ export class BaileysStartupService extends ChannelStartupService {
await this.client.groupUpdateDescription(data.groupJid, data.description); await this.client.groupUpdateDescription(data.groupJid, data.description);
return { update: 'success' }; return { update: 'success' };
} catch { } catch (error) {
throw new InternalServerErrorException('Error updating group description', error.toString()); throw new InternalServerErrorException('Error updating group description', error.toString());
} }
} }
@@ -4437,7 +4437,7 @@ export class BaileysStartupService extends ChannelStartupService {
isCommunityAnnounce: group.isCommunityAnnounce, isCommunityAnnounce: group.isCommunityAnnounce,
linkedParent: group.linkedParent, linkedParent: group.linkedParent,
}; };
} catch { } catch (error) {
if (reply === 'inner') { if (reply === 'inner') {
return; return;
} }
@@ -4484,7 +4484,7 @@ export class BaileysStartupService extends ChannelStartupService {
try { try {
const code = await this.client.groupInviteCode(id.groupJid); const code = await this.client.groupInviteCode(id.groupJid);
return { inviteUrl: `https://chat.whatsapp.com/${code}`, inviteCode: code }; return { inviteUrl: `https://chat.whatsapp.com/${code}`, inviteCode: code };
} catch { } catch (error) {
throw new NotFoundException('No invite code', error.toString()); throw new NotFoundException('No invite code', error.toString());
} }
} }
@@ -4524,7 +4524,7 @@ export class BaileysStartupService extends ChannelStartupService {
try { try {
const groupJid = await this.client.groupAcceptInvite(id.inviteCode); const groupJid = await this.client.groupAcceptInvite(id.inviteCode);
return { accepted: true, groupJid: groupJid }; return { accepted: true, groupJid: groupJid };
} catch { } catch (error) {
throw new NotFoundException('Accept invite error', error.toString()); throw new NotFoundException('Accept invite error', error.toString());
} }
} }
@@ -4533,7 +4533,7 @@ export class BaileysStartupService extends ChannelStartupService {
try { try {
const inviteCode = await this.client.groupRevokeInvite(id.groupJid); const inviteCode = await this.client.groupRevokeInvite(id.groupJid);
return { revoked: true, inviteCode }; return { revoked: true, inviteCode };
} catch { } catch (error) {
throw new NotFoundException('Revoke error', error.toString()); throw new NotFoundException('Revoke error', error.toString());
} }
} }
@@ -4559,7 +4559,7 @@ export class BaileysStartupService extends ChannelStartupService {
} }
return { participants: parsedParticipants }; return { participants: parsedParticipants };
} catch { } catch (error) {
console.error(error); console.error(error);
throw new NotFoundException('No participants', error.toString()); throw new NotFoundException('No participants', error.toString());
} }
@@ -4574,7 +4574,7 @@ export class BaileysStartupService extends ChannelStartupService {
update.action, update.action,
); );
return { updateParticipants: updateParticipants }; return { updateParticipants: updateParticipants };
} catch { } catch (error) {
throw new BadRequestException('Error updating participants', error.toString()); throw new BadRequestException('Error updating participants', error.toString());
} }
} }
@@ -4583,7 +4583,7 @@ export class BaileysStartupService extends ChannelStartupService {
try { try {
const updateSetting = await this.client.groupSettingUpdate(update.groupJid, update.action); const updateSetting = await this.client.groupSettingUpdate(update.groupJid, update.action);
return { updateSetting: updateSetting }; return { updateSetting: updateSetting };
} catch { } catch (error) {
throw new BadRequestException('Error updating setting', error.toString()); throw new BadRequestException('Error updating setting', error.toString());
} }
} }
@@ -4592,7 +4592,7 @@ export class BaileysStartupService extends ChannelStartupService {
try { try {
await this.client.groupToggleEphemeral(update.groupJid, update.expiration); await this.client.groupToggleEphemeral(update.groupJid, update.expiration);
return { success: true }; return { success: true };
} catch { } catch (error) {
throw new BadRequestException('Error updating setting', error.toString()); throw new BadRequestException('Error updating setting', error.toString());
} }
} }
@@ -4601,7 +4601,7 @@ export class BaileysStartupService extends ChannelStartupService {
try { try {
await this.client.groupLeave(id.groupJid); await this.client.groupLeave(id.groupJid);
return { groupJid: id.groupJid, leave: true }; return { groupJid: id.groupJid, leave: true };
} catch { } catch (error) {
throw new BadRequestException('Unable to leave the group', error.toString()); throw new BadRequestException('Unable to leave the group', error.toString());
} }
} }
@@ -4885,7 +4885,7 @@ export class BaileysStartupService extends ChannelStartupService {
const response = await this.client.signalRepository.decryptMessage({ jid, type, ciphertext: ciphertextBuffer }); const response = await this.client.signalRepository.decryptMessage({ jid, type, ciphertext: ciphertextBuffer });
return response instanceof Uint8Array ? Buffer.from(response).toString('base64') : response; return response instanceof Uint8Array ? Buffer.from(response).toString('base64') : response;
} catch { } catch (error) {
this.logger.error('Error decrypting message:'); this.logger.error('Error decrypting message:');
this.logger.error(error); this.logger.error(error);
throw error; throw error;
@@ -4943,7 +4943,7 @@ export class BaileysStartupService extends ChannelStartupService {
catalogLength: productsCatalog.length, catalogLength: productsCatalog.length,
catalog: productsCatalog, catalog: productsCatalog,
}; };
} catch { } catch (error) {
console.log(error); console.log(error);
return { wuid: jid, name: null, isBusiness: false }; return { wuid: jid, name: null, isBusiness: false };
} }
@@ -4964,7 +4964,7 @@ export class BaileysStartupService extends ChannelStartupService {
} }
return catalog; return catalog;
} catch { } catch (error) {
throw new InternalServerErrorException('Error getCatalog', error.toString()); throw new InternalServerErrorException('Error getCatalog', error.toString());
} }
} }
@@ -5008,7 +5008,7 @@ export class BaileysStartupService extends ChannelStartupService {
} }
return result.collections; return result.collections;
} catch { } catch (error) {
throw new InternalServerErrorException('Error getCatalog', error.toString()); throw new InternalServerErrorException('Error getCatalog', error.toString());
} }
} }
@@ -5361,7 +5361,7 @@ export class BaileysStartupService extends ChannelStartupService {
results, results,
}, },
}; };
} catch { } catch (error) {
this.logger.error(`Error decrypting poll votes: ${error}`); this.logger.error(`Error decrypting poll votes: ${error}`);
throw new InternalServerErrorException('Error decrypting poll votes', error.toString()); throw new InternalServerErrorException('Error decrypting poll votes', error.toString());
} }