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:
@@ -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) {
|
||||
|
||||
@@ -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 {};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user