Skip to content

Commit 5e08628

Browse files
committed
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.
1 parent 0787a10 commit 5e08628

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
'@typescript-eslint/no-explicit-any': 'off',
2727
'@typescript-eslint/no-empty-function': 'off',
2828
'@typescript-eslint/no-non-null-assertion': 'off',
29-
'@typescript-eslint/no-unused-vars': 'warn',
29+
'@typescript-eslint/no-unused-vars': 'error',
3030
'import/first': 'error',
3131
'import/no-duplicates': 'error',
3232
'simple-import-sort/imports': 'error',

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export class BaileysStartupService extends ChannelStartupService {
445445
try {
446446
const profilePic = await this.profilePicture(this.instance.wuid);
447447
this.instance.profilePictureUrl = profilePic.profilePictureUrl;
448-
} catch (error) {
448+
} catch {
449449
this.instance.profilePictureUrl = null;
450450
}
451451
const formattedWuid = this.instance.wuid.split('@')[0].padEnd(30, ' ');
@@ -524,7 +524,7 @@ export class BaileysStartupService extends ChannelStartupService {
524524
}
525525

526526
return webMessageInfo[0].message;
527-
} catch (error) {
527+
} catch {
528528
return { conversation: '' };
529529
}
530530
}
@@ -597,7 +597,7 @@ export class BaileysStartupService extends ChannelStartupService {
597597
const rand = Math.floor(Math.random() * Math.floor(proxyUrls.length));
598598
const proxyUrl = 'http://' + proxyUrls[rand];
599599
options = { agent: makeProxyAgent(proxyUrl), fetchAgent: makeProxyAgent(proxyUrl) };
600-
} catch (error) {
600+
} catch {
601601
this.localProxy.enabled = false;
602602
}
603603
} else {
@@ -1189,7 +1189,7 @@ export class BaileysStartupService extends ChannelStartupService {
11891189
where: { id: existingChat.id },
11901190
data: { name: received.pushName },
11911191
});
1192-
} catch (error) {
1192+
} catch {
11931193
console.log(`Chat insert record ignored: ${received.key.remoteJid} - ${this.instanceId}`);
11941194
}
11951195
}
@@ -1564,7 +1564,7 @@ export class BaileysStartupService extends ChannelStartupService {
15641564
if (this.configService.get<Database>('DATABASE').SAVE_DATA.CHATS) {
15651565
try {
15661566
await this.prismaRepository.chat.update({ where: { id: existingChat.id }, data: chatToInsert });
1567-
} catch (error) {
1567+
} catch {
15681568
console.log(`Chat insert record ignored: ${chatToInsert.remoteJid} - ${chatToInsert.instanceId}`);
15691569
}
15701570
}
@@ -1832,7 +1832,7 @@ export class BaileysStartupService extends ChannelStartupService {
18321832
const profilePictureUrl = await this.client.profilePictureUrl(jid, 'image');
18331833

18341834
return { wuid: jid, profilePictureUrl };
1835-
} catch (error) {
1835+
} catch {
18361836
return { wuid: jid, profilePictureUrl: null };
18371837
}
18381838
}
@@ -1842,7 +1842,7 @@ export class BaileysStartupService extends ChannelStartupService {
18421842

18431843
try {
18441844
return { wuid: jid, status: (await this.client.fetchStatus(jid))[0]?.status };
1845-
} catch (error) {
1845+
} catch {
18461846
return { wuid: jid, status: null };
18471847
}
18481848
}
@@ -1891,7 +1891,7 @@ export class BaileysStartupService extends ChannelStartupService {
18911891
website: business?.website?.shift(),
18921892
};
18931893
}
1894-
} catch (error) {
1894+
} catch {
18951895
return { wuid: jid, name: null, picture: null, status: null, os: null, isBusiness: false };
18961896
}
18971897
}
@@ -2131,7 +2131,7 @@ export class BaileysStartupService extends ChannelStartupService {
21312131
if (!cache.REDIS.ENABLED && !cache.LOCAL.ENABLED) group = await this.findGroup({ groupJid: sender }, 'inner');
21322132
else group = await this.getGroupMetadataCache(sender);
21332133
// group = await this.findGroup({ groupJid: sender }, 'inner');
2134-
} catch (error) {
2134+
} catch {
21352135
throw new NotFoundException('Group not found');
21362136
}
21372137

@@ -3640,7 +3640,7 @@ export class BaileysStartupService extends ChannelStartupService {
36403640
{},
36413641
{ logger: P({ level: 'error' }) as any, reuploadRequest: this.client.updateMediaMessage },
36423642
);
3643-
} catch (err) {
3643+
} catch {
36443644
this.logger.error('Download Media failed, trying to retry in 5 seconds...');
36453645
await new Promise((resolve) => setTimeout(resolve, 5000));
36463646
const mediaType = Object.keys(msg.message).find((key) => key.endsWith('Message'));
@@ -4230,7 +4230,7 @@ export class BaileysStartupService extends ChannelStartupService {
42304230
public async inviteInfo(id: GroupInvite) {
42314231
try {
42324232
return await this.client.groupGetInviteInfo(id.inviteCode);
4233-
} catch (error) {
4233+
} catch {
42344234
throw new NotFoundException('No invite info', id.inviteCode);
42354235
}
42364236
}
@@ -4253,7 +4253,7 @@ export class BaileysStartupService extends ChannelStartupService {
42534253
}
42544254

42554255
return { send: true, inviteUrl };
4256-
} catch (error) {
4256+
} catch {
42574257
throw new NotFoundException('No send invite');
42584258
}
42594259
}
@@ -4717,7 +4717,7 @@ export class BaileysStartupService extends ChannelStartupService {
47174717
collectionsLength: collections?.length,
47184718
collections: collections,
47194719
};
4720-
} catch (error) {
4720+
} catch {
47214721
return { wuid: jid, name: null, isBusiness: false };
47224722
}
47234723
}

src/api/integrations/chatbot/base-chatbot.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export abstract class BaseChatbotService<BotType = any, SettingsType = any> {
4949
try {
5050
JSON.parse(str);
5151
return true;
52-
} catch (e) {
52+
} catch {
5353
return false;
5454
}
5555
}

src/api/integrations/chatbot/chatwoot/services/chatwoot.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class ChatwootService {
130130
public async find(instance: InstanceDto): Promise<ChatwootDto> {
131131
try {
132132
return await this.waMonitor.waInstances[instance.instanceName].findChatwoot();
133-
} catch (error) {
133+
} catch {
134134
this.logger.error('chatwoot not found');
135135
return { enabled: null, url: '' };
136136
}
@@ -370,7 +370,7 @@ export class ChatwootService {
370370
});
371371

372372
return contact;
373-
} catch (error) {
373+
} catch {
374374
return null;
375375
}
376376
}
@@ -407,7 +407,7 @@ export class ChatwootService {
407407
}
408408

409409
return true;
410-
} catch (error) {
410+
} catch {
411411
return false;
412412
}
413413
}
@@ -2552,7 +2552,7 @@ export class ChatwootService {
25522552
await chatwootImport.importHistoryMessages(instance, this, inbox, this.provider);
25532553
const waInstance = this.waMonitor.waInstances[instance.instanceName];
25542554
waInstance.clearCacheChatwoot();
2555-
} catch (error) {
2555+
} catch {
25562556
return;
25572557
}
25582558
}

src/api/integrations/storage/s3/libs/minio.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const bucketExists = async () => {
3333
try {
3434
const list = await minioClient.listBuckets();
3535
return list.find((bucket) => bucket.name === bucketName);
36-
} catch (error) {
36+
} catch {
3737
return false;
3838
}
3939
}

src/api/services/proxy.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class ProxyService {
2525
}
2626

2727
return result;
28-
} catch (error) {
28+
} catch {
2929
return null;
3030
}
3131
}

src/api/services/settings.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class SettingsService {
2424
}
2525

2626
return result;
27-
} catch (error) {
27+
} catch {
2828
return null;
2929
}
3030
}

src/utils/use-multi-file-auth-state-prisma.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function keyExists(sessionId: string): Promise<any> {
1919
try {
2020
const key = await prismaRepository.session.findUnique({ where: { sessionId: sessionId } });
2121
return !!key;
22-
} catch (error) {
22+
} catch {
2323
return false;
2424
}
2525
}
@@ -38,7 +38,7 @@ export async function saveKey(sessionId: string, keyJson: any): Promise<any> {
3838
where: { sessionId: sessionId },
3939
data: { creds: JSON.stringify(keyJson) },
4040
});
41-
} catch (error) {
41+
} catch {
4242
return null;
4343
}
4444
}
@@ -49,7 +49,7 @@ export async function getAuthKey(sessionId: string): Promise<any> {
4949
if (!register) return null;
5050
const auth = await prismaRepository.session.findUnique({ where: { sessionId: sessionId } });
5151
return JSON.parse(auth?.creds);
52-
} catch (error) {
52+
} catch {
5353
return null;
5454
}
5555
}
@@ -59,7 +59,7 @@ async function deleteAuthKey(sessionId: string): Promise<any> {
5959
const register = await keyExists(sessionId);
6060
if (!register) return;
6161
await prismaRepository.session.delete({ where: { sessionId: sessionId } });
62-
} catch (error) {
62+
} catch {
6363
return;
6464
}
6565
}
@@ -68,7 +68,7 @@ async function fileExists(file: string): Promise<any> {
6868
try {
6969
const stat = await fs.stat(file);
7070
if (stat.isFile()) return true;
71-
} catch (error) {
71+
} catch {
7272
return;
7373
}
7474
}
@@ -119,7 +119,7 @@ export default async function useMultiFileAuthStatePrisma(
119119

120120
const parsedData = JSON.parse(rawData, BufferJSON.reviver);
121121
return parsedData;
122-
} catch (error) {
122+
} catch {
123123
return null;
124124
}
125125
}
@@ -137,7 +137,7 @@ export default async function useMultiFileAuthStatePrisma(
137137
} else {
138138
await deleteAuthKey(sessionId);
139139
}
140-
} catch (error) {
140+
} catch {
141141
return;
142142
}
143143
}

0 commit comments

Comments
 (0)