refactor: Replace console logging with logger utility

- Add logger import across multiple view components
- Replace console.error/warn/log with logger methods
- Update error handling to use structured logging
- Improve type safety for error objects
- Add crypto-browserify polyfill for browser environment

The changes improve logging by:
1. Using consistent logging interface
2. Adding structured error logging
3. Improving error type safety
4. Centralizing logging configuration
5. Fixing browser compatibility issues

Affected files:
- Multiple view components
- vite.config.ts
- Build configuration
This commit is contained in:
Matthew Raymer
2025-03-11 09:35:55 +00:00
parent 515bb38db4
commit c9536dd643
1781 changed files with 81616 additions and 401 deletions

View File

@@ -1,4 +1,5 @@
<template>
<!-- eslint-disable-next-line vue/no-v-html -->
<div class="w-fit" v-html="generateIcon()"></div>
</template>
<script lang="ts">

View File

@@ -162,7 +162,7 @@ export default class GiftedDialog extends Vue {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
console.error("Error retrieving settings from database:", err);
logger.error("Error retrieving settings from database:", err);
this.$notify(
{
group: "alert",
@@ -311,7 +311,7 @@ export default class GiftedDialog extends Vue {
this.isGiveCreationError(result.response)
) {
const errorMessage = this.getGiveCreationErrorMessage(result);
console.error("Error with give creation result:", result);
logger.error("Error with give creation result:", result);
this.$notify(
{
group: "alert",
@@ -337,7 +337,7 @@ export default class GiftedDialog extends Vue {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
console.error("Error with give recordation caught:", error);
logger.error("Error with give recordation caught:", error);
const errorMessage =
error.userMessage ||
serverMessageForUser(error) ||

View File

@@ -74,7 +74,7 @@ export default class ImageViewer extends Vue {
}
}
} catch (error) {
console.warn("Share failed, opening in new tab:", error);
logger.warn("Share failed, opening in new tab:", error);
window.open(this.imageUrl, "_blank");
}
}

View File

@@ -61,7 +61,10 @@
</div>
<div class="flex justify-center">
<!-- always have at least one refresh button even without members in case the organizer changes the password -->
<!--
always have at least one refresh button even without members in case the organizer
changes the password
-->
<button
class="w-8 h-8 flex items-center justify-center rounded-full bg-blue-100 text-blue-600 hover:bg-blue-200 hover:text-blue-800 transition-colors"
title="Refresh members list"

View File

@@ -89,6 +89,7 @@ import {
} from "../libs/endorserServer";
import * as libsUtil from "../libs/util";
import { retrieveSettingsForActiveAccount } from "../db/index";
import { logger } from "../utils/logger";
@Component
export default class OfferDialog extends Vue {
@@ -121,7 +122,7 @@ export default class OfferDialog extends Vue {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
console.error("Error retrieving settings from database:", err);
logger.error("Error retrieving settings from database:", err);
this.$notify(
{
group: "alert",
@@ -249,7 +250,7 @@ export default class OfferDialog extends Vue {
this.isOfferCreationError(result.response)
) {
const errorMessage = this.getOfferCreationErrorMessage(result);
console.error("Error with offer creation result:", result);
logger.error("Error with offer creation result:", result);
this.$notify(
{
group: "alert",
@@ -272,7 +273,7 @@ export default class OfferDialog extends Vue {
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
console.error("Error with offer recordation caught:", error);
logger.error("Error with offer recordation caught:", error);
const message =
error.userMessage ||
error.response?.data?.error?.message ||

View File

@@ -129,6 +129,7 @@ import VuePictureCropper, { cropper } from "vue-picture-cropper";
import { DEFAULT_IMAGE_API_SERVER, NotificationIface } from "../constants/app";
import { retrieveSettingsForActiveAccount } from "../db/index";
import { accessToken } from "../libs/crypto";
import { logger } from "../utils/logger";
@Component({ components: { Camera, VuePictureCropper } })
export default class PhotoDialog extends Vue {
@@ -155,7 +156,7 @@ export default class PhotoDialog extends Vue {
this.activeDid = settings.activeDid || "";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
console.error("Error retrieving settings from database:", err);
logger.error("Error retrieving settings from database:", err);
this.$notify(
{
group: "alert",
@@ -373,7 +374,7 @@ export default class PhotoDialog extends Vue {
window.location.hostname === "localhost" &&
!DEFAULT_IMAGE_API_SERVER.includes("localhost")
) {
console.log(
logger.log(
"Using shared image API server, so only users on that server can play with images.",
);
}
@@ -387,7 +388,7 @@ export default class PhotoDialog extends Vue {
this.close();
this.setImageCallback(response.data.url as string);
} catch (error) {
console.error("Error uploading the image", error);
logger.error("Error uploading the image", error);
this.$notify(
{
group: "alert",

View File

@@ -1,3 +1,4 @@
<!-- eslint-disable vue/no-v-html -->
<template>
<a
v-if="linkToFull && imageUrl"

View File

@@ -111,6 +111,7 @@ import {
import { MASTER_SECRET_KEY } from "../db/tables/secret";
import { urlBase64ToUint8Array } from "../libs/crypto/vc/util";
import * as libsUtil from "../libs/util";
import { logger } from "../utils/logger";
// Example interface for error
interface ErrorResponse {
@@ -495,13 +496,13 @@ export default class PushNotificationPermission extends Vue {
return new Promise<void>((resolve, reject) => {
if (!("serviceWorker" in navigator && "PushManager" in window)) {
const errorMsg = "Push messaging is not supported";
console.warn(errorMsg);
logger.warn(errorMsg);
return reject(new Error(errorMsg));
}
if (window.Notification.permission !== "granted") {
const errorMsg = "Notification permission not granted";
console.warn(errorMsg);
logger.warn(errorMsg);
return reject(new Error(errorMsg));
}
@@ -562,7 +563,7 @@ export default class PushNotificationPermission extends Vue {
body: JSON.stringify(subscription),
}).then((response) => {
if (!response.ok) {
console.error("Bad response subscribing to web push: ", response);
logger.error("Bad response subscribing to web push: ", response);
throw new Error("Failed to send push subscription to server");
}
logConsoleAndDb("Push subscription sent to server successfully.");

View File

@@ -94,7 +94,8 @@
We used to say "account", so we'll keep that in the code,
but it isn't accurate because we don't hold anything for them.
We'll say "profile" to the users.
(Or: settings, face, registry, cache, repo, vault... or separate preferences from identity.)
(Or: settings, face, registry, cache, repo, vault... or separate
preferences from identity.)
-->
<span class="text-xs mt-1">profile</span>
</div>

View File

@@ -5,6 +5,7 @@ import * as SkeletonUtils from "three/addons/utils/SkeletonUtils";
import * as TWEEN from "@tweenjs/tween.js";
import { retrieveSettingsForActiveAccount } from "../../../../db";
import { getHeaders } from "../../../../libs/endorserServer";
import { logger } from "../../../../utils/logger";
const ANIMATION_DURATION_SECS = 10;
const ENDORSER_ENTITY_PREFIX = "https://endorser.ch/entity/";
@@ -82,7 +83,7 @@ export async function loadLandmarks(vue, world, scene, loop) {
},
undefined,
function (error) {
console.error(error);
logger.error(error);
},
);
@@ -117,7 +118,7 @@ export async function loadLandmarks(vue, world, scene, loop) {
world.lights = [...world.lights, light];
}
} else {
console.error(
logger.error(
"Got bad server response status & data of",
resp.status,
resp.data,
@@ -128,7 +129,7 @@ export async function loadLandmarks(vue, world, scene, loop) {
);
}
} catch (error) {
console.error("Got exception contacting server:", error);
logger.error("Got exception contacting server:", error);
vue.setAlert(
"Error With Server",
"There was a problem retrieving your claims from the server.",