Skip to content

Commit

Permalink
fix(app): adding more log details for the resetting process
Browse files Browse the repository at this point in the history
  • Loading branch information
nutrina committed Jan 20, 2023
1 parent b9ecd81 commit 0ed5d92
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
16 changes: 15 additions & 1 deletion app/components/RefreshStampModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { CeramicContext } from "../context/ceramicContext";
import { Progress, completedIcon, Status, Step } from "./Progress";
import { useToast } from "@chakra-ui/react";

// --- Datadog
import { datadogLogs } from "@datadog/browser-logs";

export type RefreshStampModalProps = {
isOpen: boolean;
onClose: () => void;
};

export const RefreshStampModal = ({ isOpen, onClose }: RefreshStampModalProps) => {
const { handleCheckRefreshPassport } = useContext(CeramicContext);
const { handleCheckRefreshPassport, userDid } = useContext(CeramicContext);
const [resetError, setResetError] = useState<boolean>(false);
const toast = useToast();

Expand Down Expand Up @@ -64,15 +67,26 @@ export const RefreshStampModal = ({ isOpen, onClose }: RefreshStampModalProps) =
const refreshPassportState = async () => {
try {
updateSteps(1);
datadogLogs.logger.info(`RefreshStampModal - calling handleCheckRefreshPassport for did=${userDid}`, {
did: userDid,
});
const refreshedState = await (await handleCheckRefreshPassport()).filter((state: boolean) => !state);
// If errors were found while refreshing they won't be filtered out
if (refreshedState.length > 0) {
datadogLogs.logger.error(
`RefreshStampModal - calling handleCheckRefreshPassport was not successfull for did=${userDid}`,
{ did: userDid }
);
// handleCheckRefreshPassport returned an error after polling ceramic
updateSteps(2, true);
// show error status in progress bar for 2 seconds
await new Promise((resolve) => setTimeout(resolve, 2000));
setResetError(true);
} else {
datadogLogs.logger.info(
`RefreshStampModal - calling handleCheckRefreshPassport was successfull for did=${userDid}`,
{ did: userDid }
);
updateSteps(2);
// Wait 2 seconds to show success toast
await new Promise((resolve) => setTimeout(resolve, 2000));
Expand Down
14 changes: 9 additions & 5 deletions database-client/src/ceramicClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class CeramicDatabase implements DataStorageBase {
const rest = await axios.get(streamUrl);
return false;
} catch (e) {
this.logger.error(`Error when calling getRecordDocument on Passport`, e);
this.logger.error(`checkPassportCACAOError - Error when calling getRecordDocument on Passport`, {error:e});
if (e?.response?.data?.error?.includes("CACAO has expired")) {
return true;
}
Expand All @@ -116,20 +116,24 @@ export class CeramicDatabase implements DataStorageBase {

let passportDoc
try {
this.logger.info("refreshPassport - getRecordDocument");
passportDoc = await this.store.getRecordDocument(this.model.getDefinitionID("Passport"));
} catch (e) {
this.logger.info("refreshPassport - failed to get record document", {error:e});
// unable to get passport doc
return false;
}
// Attempt to load stream 36 times, with 5 second delay between each attempt - 5 min total
while (attempts < 36 && !success) {
const options = attempts === 1 ? { sync: SyncOptions.SYNC_ALWAYS, syncTimeoutSeconds: 5 } : { };
try {
this.logger.info(`refreshPassport - loading stream with SyncOptions.SYNC_ALWAYS, attempt:${attempts}, stream=${passportDoc.id}`, {options:options});
await this.ceramicClient.loadStream<TileDocument>(passportDoc.id, options);
success = true;
this.logger.info(`refreshPassport - loading stream with SyncOptions.SYNC_ALWAYS, attempt:${attempts}, stream=${passportDoc.id} => SUCCESS`);
return success;
} catch (e) {
this.logger.error(`Error when calling loadStream on passport, attempt ${attempts}`, e);
this.logger.error(`refreshPassport - error when calling loadStream on passport, attempt ${attempts}`, {error: e});
attempts++;
await new Promise((resolve) => setTimeout(resolve, 5000));
}
Expand Down Expand Up @@ -169,7 +173,7 @@ export class CeramicDatabase implements DataStorageBase {
} as Stamp;
} catch (e) {
this.logger.error(
`Error when loading stamp with streamId ${streamIDs[idx]} for did ${this.did}:` + e.toString()
`Error when loading stamp with streamId ${streamIDs[idx]} for did ${this.did}:` + e.toString(), {error: e}
);
throw e;
}
Expand All @@ -194,14 +198,14 @@ export class CeramicDatabase implements DataStorageBase {
const passportDoc = await this.store.getRecordDocument(this.model.getDefinitionID("Passport"));
await this.ceramicClient.pin.add(passportDoc.id);
} catch (e) {
this.logger.error(`Error when pinning passport for did ${this.did}:` + e.toString());
this.logger.error(`Error when pinning passport for did ${this.did}:` + e.toString(), {error: e});
}

return {
passport: parsedPassport,
};
} catch (e) {
this.logger.error(`Error when loading passport for did ${this.did}:` + e.toString());
this.logger.error(`Error when loading passport for did ${this.did}:` + e.toString(), {error: e});
// Indicate there was an error loading passport
errors.error = true;
errors.passport = true
Expand Down

0 comments on commit 0ed5d92

Please sign in to comment.