Skip to content

Commit

Permalink
catch and log errors other than no-chage updates
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Sep 26, 2024
1 parent 258f590 commit 26a172c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/agent/src/agent-did-resolver-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,31 @@ export class AgentDidResolverCache extends DidResolverCacheLevel implements DidR
if (!this._resolving.has(did) && Date.now() >= cachedResult.ttlMillis) {
this._resolving.set(did, true);

// if a DID is stored in the DID Store, then we don't want to evict it from the cache until we have a successful resolution
// upon a successful resolution, we will update both the storage and the cache with the newly resolved Document.
const storedDid = await this.agent.did.get({ didUri: did, tenant: this.agent.agentDid.uri });
if ('undefined' !== typeof storedDid) {
try {
const result = await this.agent.did.resolve(did);

// if the resolution was successful, update the stored DID with the new Document
if (!result.didResolutionMetadata.error && result.didDocument) {

const portableDid = {
...storedDid,
document : result.didDocument,
metadata : result.didDocumentMetadata,
};
await this.agent.did.update({ portableDid, tenant: this.agent.agentDid.uri });

// this will throw an error if the DID is not managed by the agent, or there is no difference between the stored and resolved DID
try {
await this.agent.did.update({ portableDid, tenant: this.agent.agentDid.uri });
} catch(error: any) {
// if the error is not due to no changes detected, log the error
if (error.message && !error.message.includes('No changes detected, update aborted')) {
console.log(`Error updating DID: ${error.message}`);
}
}

Check warning on line 75 in packages/agent/src/agent-did-resolver-cache.ts

View check run for this annotation

Codecov / codecov/patch

packages/agent/src/agent-did-resolver-cache.ts#L57-L75

Added lines #L57 - L75 were not covered by tests
}
} finally {
this._resolving.delete(did);
Expand Down

0 comments on commit 26a172c

Please sign in to comment.