diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index 23eed625..5c7073b3 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -511,30 +511,76 @@ export async function getPlanFromCache( "/api/v2/report/plans?handleId=" + encodeURIComponent(handleId); const headers = await getHeaders(requesterDid); + + // Enhanced diagnostic logging for plan loading + const requestId = `plan_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; + + logger.info("[Plan Loading] 🔍 Loading plan from server:", { + requestId, + handleId, + apiServer, + endpoint: url, + requesterDid, + timestamp: new Date().toISOString(), + }); + try { const resp = await axios.get(url, { headers }); + + logger.info("[Plan Loading] ✅ Plan loaded successfully:", { + requestId, + handleId, + status: resp.status, + hasData: !!resp.data?.data, + dataLength: resp.data?.data?.length || 0, + timestamp: new Date().toISOString(), + }); + if (resp.status === 200 && resp.data?.data?.length > 0) { cred = resp.data.data[0]; planCache.set(handleId, cred); + + logger.debug("[Plan Loading] 💾 Plan cached:", { + requestId, + handleId, + planName: cred?.name, + planIssuer: cred?.issuerDid, + }); } else { // Use debug level for development to reduce console noise const isDevelopment = process.env.VITE_PLATFORM === "development"; const log = isDevelopment ? logger.debug : logger.log; log( - "[EndorserServer] Plan cache is empty for handle", + "[Plan Loading] ⚠️ Plan cache is empty for handle", handleId, " Got data:", JSON.stringify(resp.data), ); } } catch (error) { - logger.error( - "[EndorserServer] Failed to load plan with handle", + // Enhanced error logging for plan loading failures + const axiosError = error as { + response?: { + data?: unknown; + status?: number; + statusText?: string; + }; + message?: string; + }; + + logger.error("[Plan Loading] ❌ Failed to load plan:", { + requestId, handleId, - " Got error:", - JSON.stringify(error), - ); + apiServer, + endpoint: url, + requesterDid, + errorStatus: axiosError.response?.status, + errorStatusText: axiosError.response?.statusText, + errorData: axiosError.response?.data, + errorMessage: axiosError.message || String(error), + timestamp: new Date().toISOString(), + }); } } return cred; @@ -1018,19 +1064,82 @@ export async function createAndSubmitClaim( const vcJwt: string = await createEndorserJwtForDid(issuerDid, vcPayload); + // Enhanced diagnostic logging for claim submission + const requestId = `claim_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; + + logger.info("[Claim Submission] 🚀 Starting claim submission:", { + requestId, + apiServer, + requesterDid: issuerDid, + endpoint: `${apiServer}/api/v2/claim`, + timestamp: new Date().toISOString(), + jwtLength: vcJwt.length, + }); + // Make the xhr request payload const payload = JSON.stringify({ jwtEncoded: vcJwt }); const url = `${apiServer}/api/v2/claim`; + logger.debug("[Claim Submission] 📡 Making API request:", { + requestId, + url, + payloadSize: payload.length, + headers: { "Content-Type": "application/json" }, + }); + const response = await axios.post(url, payload, { headers: { "Content-Type": "application/json", }, }); + logger.info("[Claim Submission] ✅ Claim submitted successfully:", { + requestId, + status: response.status, + handleId: response.data?.handleId, + responseSize: JSON.stringify(response.data).length, + timestamp: new Date().toISOString(), + }); + return { success: true, handleId: response.data?.handleId }; } catch (error: unknown) { - logger.error("Error submitting claim:", error); + // Enhanced error logging with comprehensive context + const requestId = `claim_error_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; + + const axiosError = error as { + response?: { + data?: { error?: { code?: string; message?: string } }; + status?: number; + statusText?: string; + headers?: Record; + }; + config?: { + url?: string; + method?: string; + headers?: Record; + }; + message?: string; + }; + + logger.error("[Claim Submission] ❌ Claim submission failed:", { + requestId, + apiServer, + requesterDid: issuerDid, + endpoint: `${apiServer}/api/v2/claim`, + errorCode: axiosError.response?.data?.error?.code, + errorMessage: axiosError.response?.data?.error?.message, + httpStatus: axiosError.response?.status, + httpStatusText: axiosError.response?.statusText, + responseHeaders: axiosError.response?.headers, + requestConfig: { + url: axiosError.config?.url, + method: axiosError.config?.method, + headers: axiosError.config?.headers, + }, + originalError: axiosError.message || String(error), + timestamp: new Date().toISOString(), + }); + const errorMessage: string = serverMessageForUser(error) || (error && typeof error === "object" && "message" in error