Skip to content

Commit

Permalink
Merge pull request #143 from torusresearch/fix/error-logging
Browse files Browse the repository at this point in the history
log failed requests with final error msg
  • Loading branch information
chaitanyapotti authored May 10, 2024
2 parents 17917d8 + 1892552 commit 9e50bb8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/helpers/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ export async function retrieveOrImportShare(params: {
}),
null,
{ logTracingHeader: config.logRequestTracing }
).catch((err) => {
log.error("commitment error", err);
});
);
promiseArr.push(p);
}
// send share request once k + t number of commitment requests have completed
Expand All @@ -230,7 +228,7 @@ export async function retrieveOrImportShare(params: {
return Promise.resolve(resultArr);
} else if (importedShares?.length === 0 && completedRequests.length >= ~~((endpoints.length * 3) / 4) + 1) {
const requiredNodeResult = completedRequests.find((resp: void | JRPCResponse<CommitmentRequestResult>) => {
if (resp && resp.result?.nodeindex === "1") {
if (resp) {
return true;
}
return false;
Expand Down Expand Up @@ -294,7 +292,7 @@ export async function retrieveOrImportShare(params: {
}),
null,
{ logTracingHeader: config.logRequestTracing }
).catch((err) => log.error("share req", err));
);
promiseArrRequest.push(p);
} else {
const p = post<JRPCResponse<ShareRequestResult>>(
Expand All @@ -317,7 +315,7 @@ export async function retrieveOrImportShare(params: {
}),
null,
{ logTracingHeader: config.logRequestTracing }
).catch((err) => log.error("share req", err));
);
promiseArrRequest.push(p);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/some.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ export class SomeError<T> extends Error {
predicate: string;

constructor({ errors, responses, predicate }: { errors: Error[]; responses: T[]; predicate: string }) {
// its fine to log responses in errors logs for better debugging,
// as data is always encrypted with temp key
// temp key should not be logged anywhere
const message = `Unable to resolve enough promises.
errors: ${errors.map((x) => x?.message || x).join(", ")},
${responses.length} responses,
responses: ${JSON.stringify(responses)},
predicate error: ${predicate}`;
super(message);
this.errors = errors;
Expand Down

0 comments on commit 9e50bb8

Please sign in to comment.