forked from jsnbuchanan/crowd-funder-for-time-pwa
(chore): merge mostly pathway changes
This commit is contained in:
@@ -621,41 +621,6 @@ const planCache: LRUCache<string, PlanSummaryRecord> = new LRUCache({
|
||||
max: 500,
|
||||
});
|
||||
|
||||
/**
|
||||
* Helpful for server errors, to get all the info -- including stuff skipped by toString & JSON.stringify
|
||||
*
|
||||
* @param error
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function errorStringForLog(error: any) {
|
||||
let stringifiedError = "" + error;
|
||||
try {
|
||||
stringifiedError = JSON.stringify(error);
|
||||
} catch (e) {
|
||||
// can happen with Dexie, eg:
|
||||
// TypeError: Converting circular structure to JSON
|
||||
// --> starting at object with constructor 'DexieError2'
|
||||
// | property '_promise' -> object with constructor 'DexiePromise'
|
||||
// --- property '_value' closes the circle
|
||||
}
|
||||
let fullError = "" + error + " - JSON: " + stringifiedError;
|
||||
const errorResponseText = JSON.stringify(error.response);
|
||||
// for some reason, error.response is not included in stringify result (eg. for 400 errors on invite redemptions)
|
||||
if (!R.empty(errorResponseText) && !fullError.includes(errorResponseText)) {
|
||||
// add error.response stuff
|
||||
if (R.equals(error?.config, error?.response?.config)) {
|
||||
// but exclude "config" because it's already in there
|
||||
const newErrorResponseText = JSON.stringify(
|
||||
R.omit(["config"] as never[], error.response),
|
||||
);
|
||||
fullError += " - .response w/o same config JSON: " + newErrorResponseText;
|
||||
} else {
|
||||
fullError += " - .response JSON: " + errorResponseText;
|
||||
}
|
||||
}
|
||||
return fullError;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param handleId nullable, in which case "undefined" will be returned
|
||||
* @param requesterDid optional, in which case no private info will be returned
|
||||
@@ -710,6 +675,56 @@ export async function setPlanInCache(
|
||||
planCache.set(handleId, planSummary);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param error that is thrown from an Endorser server call by Axios
|
||||
* @returns user-friendly message, or undefined if none found
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function serverMessageForUser(error: any) {
|
||||
return (
|
||||
// this is how most user messages are returned
|
||||
error?.response?.data?.error?.message
|
||||
// some are returned as "error" with a string, but those are more for devs and are less helpful to the user
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helpful for server errors, to get all the info -- including stuff skipped by toString & JSON.stringify
|
||||
* It works with AxiosError, eg handling an error.response intelligently.
|
||||
*
|
||||
* @param error
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function errorStringForLog(error: any) {
|
||||
let stringifiedError = "" + error;
|
||||
try {
|
||||
stringifiedError = JSON.stringify(error);
|
||||
} catch (e) {
|
||||
// can happen with Dexie, eg:
|
||||
// TypeError: Converting circular structure to JSON
|
||||
// --> starting at object with constructor 'DexieError2'
|
||||
// | property '_promise' -> object with constructor 'DexiePromise'
|
||||
// --- property '_value' closes the circle
|
||||
}
|
||||
let fullError = "" + error + " - JSON: " + stringifiedError;
|
||||
const errorResponseText = JSON.stringify(error.response);
|
||||
// for some reason, error.response is not included in stringify result (eg. for 400 errors on invite redemptions)
|
||||
if (!R.empty(errorResponseText) && !fullError.includes(errorResponseText)) {
|
||||
// add error.response stuff
|
||||
if (R.equals(error?.config, error?.response?.config)) {
|
||||
// but exclude "config" because it's already in there
|
||||
const newErrorResponseText = JSON.stringify(
|
||||
R.omit(["config"] as never[], error.response),
|
||||
);
|
||||
fullError += " - .response w/o same config JSON: " + newErrorResponseText;
|
||||
} else {
|
||||
fullError += " - .response JSON: " + errorResponseText;
|
||||
}
|
||||
}
|
||||
return fullError;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns { data: Array<OfferSummaryRecord>, hitLimit: boolean true if maximum was hit and there may be more }
|
||||
@@ -1113,7 +1128,7 @@ export async function createAndSubmitClaim(
|
||||
} catch (error: any) {
|
||||
console.error("Error submitting claim:", error);
|
||||
const errorMessage: string =
|
||||
error.response?.data?.error?.message ||
|
||||
serverMessageForUser(error) ||
|
||||
error.message ||
|
||||
"Got some error submitting the claim. Check your permissions, network, and error logs.";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user