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.
This commit is contained in:
Davidson Gomes 2025-09-18 14:59:33 -03:00
parent 0787a10f39
commit 5e08628d89
8 changed files with 29 additions and 29 deletions

View File

@ -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',

View File

@ -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>('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 };
}
}

View File

@ -49,7 +49,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
try {
JSON.parse(str);
return true;
} catch (e) {
} catch {
return false;
}
}

View File

@ -130,7 +130,7 @@ export class ChatwootService {
public async find(instance: InstanceDto): Promise<ChatwootDto> {
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;
}
}

View File

@ -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;
}
}

View File

@ -25,7 +25,7 @@ export class ProxyService {
}
return result;
} catch (error) {
} catch {
return null;
}
}

View File

@ -24,7 +24,7 @@ export class SettingsService {
}
return result;
} catch (error) {
} catch {
return null;
}
}

View File

@ -19,7 +19,7 @@ export async function keyExists(sessionId: string): Promise<any> {
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<any> {
where: { sessionId: sessionId },
data: { creds: JSON.stringify(keyJson) },
});
} catch (error) {
} catch {
return null;
}
}
@ -49,7 +49,7 @@ export async function getAuthKey(sessionId: string): Promise<any> {
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<any> {
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<any> {
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;
}
}