From 5e08628d8934a36e5f4ec903891f705b5844d7f4 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Thu, 18 Sep 2025 14:59:33 -0300 Subject: [PATCH] refactor(eslint): change unused vars rule to error and update error handling in services - Update ESLint configuration to set `@typescript-eslint/no-unused-vars` from 'warn' to 'error' for stricter linting. - Refactor error handling in various services to omit error variable in catch blocks for cleaner code. --- .eslintrc.js | 2 +- .../whatsapp/whatsapp.baileys.service.ts | 26 +++++++++---------- .../chatbot/base-chatbot.service.ts | 2 +- .../chatwoot/services/chatwoot.service.ts | 8 +++--- .../storage/s3/libs/minio.server.ts | 2 +- src/api/services/proxy.service.ts | 2 +- src/api/services/settings.service.ts | 2 +- src/utils/use-multi-file-auth-state-prisma.ts | 14 +++++----- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index b6a6064e..8f54a776 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -26,7 +26,7 @@ module.exports = { '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-non-null-assertion': 'off', - '@typescript-eslint/no-unused-vars': 'warn', + '@typescript-eslint/no-unused-vars': 'error', 'import/first': 'error', 'import/no-duplicates': 'error', 'simple-import-sort/imports': 'error', diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 022ea8fd..34ef1366 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -445,7 +445,7 @@ export class BaileysStartupService extends ChannelStartupService { try { const profilePic = await this.profilePicture(this.instance.wuid); this.instance.profilePictureUrl = profilePic.profilePictureUrl; - } catch (error) { + } catch { this.instance.profilePictureUrl = null; } const formattedWuid = this.instance.wuid.split('@')[0].padEnd(30, ' '); @@ -524,7 +524,7 @@ export class BaileysStartupService extends ChannelStartupService { } return webMessageInfo[0].message; - } catch (error) { + } catch { return { conversation: '' }; } } @@ -597,7 +597,7 @@ export class BaileysStartupService extends ChannelStartupService { const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length)); const proxyUrl = 'http://' + proxyUrls[rand]; options = { agent: makeProxyAgent(proxyUrl), fetchAgent: makeProxyAgent(proxyUrl) }; - } catch (error) { + } catch { this.localProxy.enabled = false; } } else { @@ -1189,7 +1189,7 @@ export class BaileysStartupService extends ChannelStartupService { where: { id: existingChat.id }, data: { name: received.pushName }, }); - } catch (error) { + } catch { console.log(`Chat insert record ignored: ${received.key.remoteJid} - ${this.instanceId}`); } } @@ -1564,7 +1564,7 @@ export class BaileysStartupService extends ChannelStartupService { if (this.configService.get('DATABASE').SAVE_DATA.CHATS) { try { await this.prismaRepository.chat.update({ where: { id: existingChat.id }, data: chatToInsert }); - } catch (error) { + } catch { console.log(`Chat insert record ignored: ${chatToInsert.remoteJid} - ${chatToInsert.instanceId}`); } } @@ -1832,7 +1832,7 @@ export class BaileysStartupService extends ChannelStartupService { const profilePictureUrl = await this.client.profilePictureUrl(jid, 'image'); return { wuid: jid, profilePictureUrl }; - } catch (error) { + } catch { return { wuid: jid, profilePictureUrl: null }; } } @@ -1842,7 +1842,7 @@ export class BaileysStartupService extends ChannelStartupService { try { return { wuid: jid, status: (await this.client.fetchStatus(jid))[0]?.status }; - } catch (error) { + } catch { return { wuid: jid, status: null }; } } @@ -1891,7 +1891,7 @@ export class BaileysStartupService extends ChannelStartupService { website: business?.website?.shift(), }; } - } catch (error) { + } catch { return { wuid: jid, name: null, picture: null, status: null, os: null, isBusiness: false }; } } @@ -2131,7 +2131,7 @@ export class BaileysStartupService extends ChannelStartupService { if (!cache.REDIS.ENABLED && !cache.LOCAL.ENABLED) group = await this.findGroup({ groupJid: sender }, 'inner'); else group = await this.getGroupMetadataCache(sender); // group = await this.findGroup({ groupJid: sender }, 'inner'); - } catch (error) { + } catch { throw new NotFoundException('Group not found'); } @@ -3640,7 +3640,7 @@ export class BaileysStartupService extends ChannelStartupService { {}, { logger: P({ level: 'error' }) as any, reuploadRequest: this.client.updateMediaMessage }, ); - } catch (err) { + } catch { this.logger.error('Download Media failed, trying to retry in 5 seconds...'); await new Promise((resolve) => setTimeout(resolve, 5000)); const mediaType = Object.keys(msg.message).find((key) => key.endsWith('Message')); @@ -4230,7 +4230,7 @@ export class BaileysStartupService extends ChannelStartupService { public async inviteInfo(id: GroupInvite) { try { return await this.client.groupGetInviteInfo(id.inviteCode); - } catch (error) { + } catch { throw new NotFoundException('No invite info', id.inviteCode); } } @@ -4253,7 +4253,7 @@ export class BaileysStartupService extends ChannelStartupService { } return { send: true, inviteUrl }; - } catch (error) { + } catch { throw new NotFoundException('No send invite'); } } @@ -4717,7 +4717,7 @@ export class BaileysStartupService extends ChannelStartupService { collectionsLength: collections?.length, collections: collections, }; - } catch (error) { + } catch { return { wuid: jid, name: null, isBusiness: false }; } } diff --git a/src/api/integrations/chatbot/base-chatbot.service.ts b/src/api/integrations/chatbot/base-chatbot.service.ts index f19cb9d4..34cb765f 100644 --- a/src/api/integrations/chatbot/base-chatbot.service.ts +++ b/src/api/integrations/chatbot/base-chatbot.service.ts @@ -49,7 +49,7 @@ export abstract class BaseChatbotService { try { JSON.parse(str); return true; - } catch (e) { + } catch { return false; } } diff --git a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts index be3d5620..5020bfa6 100644 --- a/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts +++ b/src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts @@ -130,7 +130,7 @@ export class ChatwootService { public async find(instance: InstanceDto): Promise { try { return await this.waMonitor.waInstances[instance.instanceName].findChatwoot(); - } catch (error) { + } catch { this.logger.error('chatwoot not found'); return { enabled: null, url: '' }; } @@ -370,7 +370,7 @@ export class ChatwootService { }); return contact; - } catch (error) { + } catch { return null; } } @@ -407,7 +407,7 @@ export class ChatwootService { } return true; - } catch (error) { + } catch { return false; } } @@ -2552,7 +2552,7 @@ export class ChatwootService { await chatwootImport.importHistoryMessages(instance, this, inbox, this.provider); const waInstance = this.waMonitor.waInstances[instance.instanceName]; waInstance.clearCacheChatwoot(); - } catch (error) { + } catch { return; } } diff --git a/src/api/integrations/storage/s3/libs/minio.server.ts b/src/api/integrations/storage/s3/libs/minio.server.ts index 8d296fdc..47145a4c 100644 --- a/src/api/integrations/storage/s3/libs/minio.server.ts +++ b/src/api/integrations/storage/s3/libs/minio.server.ts @@ -33,7 +33,7 @@ const bucketExists = async () => { try { const list = await minioClient.listBuckets(); return list.find((bucket) => bucket.name === bucketName); - } catch (error) { + } catch { return false; } } diff --git a/src/api/services/proxy.service.ts b/src/api/services/proxy.service.ts index 69ba87b4..a1e5b210 100644 --- a/src/api/services/proxy.service.ts +++ b/src/api/services/proxy.service.ts @@ -25,7 +25,7 @@ export class ProxyService { } return result; - } catch (error) { + } catch { return null; } } diff --git a/src/api/services/settings.service.ts b/src/api/services/settings.service.ts index 5b7ab1b8..da477c46 100644 --- a/src/api/services/settings.service.ts +++ b/src/api/services/settings.service.ts @@ -24,7 +24,7 @@ export class SettingsService { } return result; - } catch (error) { + } catch { return null; } } diff --git a/src/utils/use-multi-file-auth-state-prisma.ts b/src/utils/use-multi-file-auth-state-prisma.ts index 7278c056..0f7faa07 100644 --- a/src/utils/use-multi-file-auth-state-prisma.ts +++ b/src/utils/use-multi-file-auth-state-prisma.ts @@ -19,7 +19,7 @@ export async function keyExists(sessionId: string): Promise { try { const key = await prismaRepository.session.findUnique({ where: { sessionId: sessionId } }); return !!key; - } catch (error) { + } catch { return false; } } @@ -38,7 +38,7 @@ export async function saveKey(sessionId: string, keyJson: any): Promise { where: { sessionId: sessionId }, data: { creds: JSON.stringify(keyJson) }, }); - } catch (error) { + } catch { return null; } } @@ -49,7 +49,7 @@ export async function getAuthKey(sessionId: string): Promise { if (!register) return null; const auth = await prismaRepository.session.findUnique({ where: { sessionId: sessionId } }); return JSON.parse(auth?.creds); - } catch (error) { + } catch { return null; } } @@ -59,7 +59,7 @@ async function deleteAuthKey(sessionId: string): Promise { const register = await keyExists(sessionId); if (!register) return; await prismaRepository.session.delete({ where: { sessionId: sessionId } }); - } catch (error) { + } catch { return; } } @@ -68,7 +68,7 @@ async function fileExists(file: string): Promise { try { const stat = await fs.stat(file); if (stat.isFile()) return true; - } catch (error) { + } catch { return; } } @@ -119,7 +119,7 @@ export default async function useMultiFileAuthStatePrisma( const parsedData = JSON.parse(rawData, BufferJSON.reviver); return parsedData; - } catch (error) { + } catch { return null; } } @@ -137,7 +137,7 @@ export default async function useMultiFileAuthStatePrisma( } else { await deleteAuthKey(sessionId); } - } catch (error) { + } catch { return; } }