Skip to content

Commit

Permalink
add ui_errors to clientStats
Browse files Browse the repository at this point in the history
Whenever the user sees an error, it will be recorded in clientStats as a `stats/client_error`
  • Loading branch information
JGreenlee committed Sep 13, 2024
1 parent 690a516 commit 6c25251
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions www/js/plugin/clientStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ type StatKey =
| 'set_reminder_prefs'
| 'force_sync'
| 'open_notification'
| 'missing_keys';
| 'missing_keys'
| 'ui_error';

let appVersion;
export function getAppVersion() {
Expand All @@ -39,9 +40,9 @@ export async function addStatReading(name: StatKey, reading?: any) {
displayErrorMsg('addStatReading: db is not defined');
}

export async function addStatError(name: StatKey, errorStr: string) {
export async function addStatError(errorMsg: string) {
const db = window['cordova']?.plugins?.BEMUserCache;
const event = await getStatsEvent(name, errorStr);
const event = await getStatsEvent('ui_error', errorMsg);
logDebug('addStatError: adding CLIENT_ERROR event: ' + JSON.stringify(event));
if (db) return db.putMessage(CLIENT_ERROR, event);
displayErrorMsg('addStatError: db is not defined');
Expand Down
3 changes: 3 additions & 0 deletions www/js/plugin/logger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { addStatError } from './clientStats';

export const logDebug = (message: string) =>
window['Logger']?.log(window['Logger'].LEVEL_DEBUG, message);

Expand All @@ -19,6 +21,7 @@ export function displayErrorMsg(errorMsg: string, title?: string) {
}
const displayMsg = `━━━━\n${title}\n━━━━\n` + errorMsg;
window.alert(displayMsg);
addStatError(`${title}: ${errorMsg}`);
console.error(displayMsg);
window['Logger']?.log(window['Logger'].LEVEL_ERROR, displayMsg);
}

0 comments on commit 6c25251

Please sign in to comment.