fix: improve type safety and add error logging (#378)

- Replace 'as any' with proper type definition for error status code access
- Add error logging to sendPresenceUpdate() catch block
- Add debug logging when .env file is not found

These changes improve type safety and visibility into potential failures
without changing any core functionality.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: gavrielc <gabicohen22@yahoo.com>
This commit is contained in:
Chujiang
2026-02-23 06:11:52 +08:00
committed by GitHub
parent 856f98023c
commit 9fb1790e12
2 changed files with 7 additions and 3 deletions

View File

@@ -80,7 +80,7 @@ export class WhatsAppChannel implements Channel {
if (connection === 'close') {
this.connected = false;
const reason = (lastDisconnect?.error as any)?.output?.statusCode;
const reason = (lastDisconnect?.error as { output?: { statusCode?: number } })?.output?.statusCode;
const shouldReconnect = reason !== DisconnectReason.loggedOut;
logger.info({ reason, shouldReconnect, queuedMessages: this.outgoingQueue.length }, 'Connection closed');
@@ -103,7 +103,9 @@ export class WhatsAppChannel implements Channel {
logger.info('Connected to WhatsApp');
// Announce availability so WhatsApp relays subsequent presence updates (typing indicators)
this.sock.sendPresenceUpdate('available').catch(() => {});
this.sock.sendPresenceUpdate('available').catch((err) => {
logger.warn({ err }, 'Failed to send presence update');
});
// Build LID to phone mapping from auth state for self-chat translation
if (this.sock.user) {

View File

@@ -1,5 +1,6 @@
import fs from 'fs';
import path from 'path';
import { logger } from './logger.js';
/**
* Parse the .env file and return values for the requested keys.
@@ -12,7 +13,8 @@ export function readEnvFile(keys: string[]): Record<string, string> {
let content: string;
try {
content = fs.readFileSync(envFile, 'utf-8');
} catch {
} catch (err) {
logger.debug({ err }, '.env file not found, using defaults');
return {};
}