homebridge-homeconnect
Version:
A Homebridge plugin that connects Home Connect appliances to Apple HomeKit
33 lines • 1.15 kB
JavaScript
// Homebridge plugin for Home Connect home appliances
// Copyright © 2023-2025 Alexander Thoukydides
import { APIError } from './api-errors.js';
// Log an error
let lastLoggedError;
export function logError(log, when, err) {
try {
// Suppress duplicate reports
if (lastLoggedError === err)
return err;
lastLoggedError = err;
// Log the error message itself
log.error(`[${when}] ${String(err)}`);
// Log the request details for API errors
if (err instanceof APIError) {
log.error(`${err.request.method} ${err.request.path}`);
}
// Log any history of causes for the error
let cause = err;
let prefix = ' '.repeat(when.length + 3);
while ((cause instanceof APIError) && cause.errCause) {
cause = cause.errCause;
log.error(`${prefix}└─ ${String(cause)}`);
prefix += ' ';
}
// Log any stack backtrace
if (err instanceof Error && err.stack)
log.debug(err.stack);
}
catch { /* empty */ }
return err;
}
//# sourceMappingURL=log-error.js.map