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

@@ -48,6 +48,7 @@ import {
UserInfo,
CreateAndSubmitClaimResult,
} from "../interfaces";
import { logger } from "../utils/logger";
/**
* Standard context for schema.org data
@@ -174,8 +175,8 @@ export function isEmptyOrHiddenDid(did?: string): boolean {
* testRecursivelyOnStrings(isHiddenDid, obj); // Returns: true
*/
function testRecursivelyOnStrings(
func: (arg0: any) => boolean,
input: any,
func: (arg0: unknown) => boolean,
input: unknown,
): boolean {
// Test direct string values
if (Object.prototype.toString.call(input) === "[object String]") {
@@ -507,7 +508,7 @@ export async function getPlanFromCache(
cred = resp.data.data[0];
planCache.set(handleId, cred);
} else {
console.info(
logger.log(
"[EndorserServer] Plan cache is empty for handle",
handleId,
" Got data:",
@@ -515,7 +516,7 @@ export async function getPlanFromCache(
);
}
} catch (error) {
console.error(
logger.error(
"[EndorserServer] Failed to load plan with handle",
handleId,
" Got error:",
@@ -543,7 +544,7 @@ export async function setPlanInCache(
* @param {any} error - Error thrown from Endorser server call
* @returns {string|undefined} User-friendly message or undefined if none found
*/
export function serverMessageForUser(error: any): string | undefined {
export function serverMessageForUser(error: unknown): string | undefined {
return error?.response?.data?.error?.message;
}
@@ -554,7 +555,7 @@ export function serverMessageForUser(error: any): string | undefined {
* @param error
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function errorStringForLog(error: any) {
export function errorStringForLog(error: unknown) {
let stringifiedError = "" + error;
try {
stringifiedError = JSON.stringify(error);
@@ -984,7 +985,7 @@ export async function createAndSubmitClaim(
return { type: "success", response };
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
console.error("Error submitting claim:", error);
logger.error("Error submitting claim:", error);
const errorMessage: string =
serverMessageForUser(error) ||
error.message ||
@@ -1330,7 +1331,7 @@ export async function register(
}
return { error: message };
} else {
console.error(resp);
logger.error(resp);
return { error: "Got a server error when registering." };
}
}
@@ -1360,7 +1361,7 @@ export async function setVisibilityUtil(
}
return { success };
} else {
console.error(
logger.error(
"Got some bad server response when setting visibility: ",
resp.status,
resp,
@@ -1370,7 +1371,7 @@ export async function setVisibilityUtil(
return { error: message };
}
} catch (err) {
console.error("Got some error when setting visibility:", err);
logger.error("Got some error when setting visibility:", err);
return { error: "Check connectivity and try again." };
}
}