Skip to content

Commit

Permalink
Add Runtime error for attempt to establish Relationships to deleted I…
Browse files Browse the repository at this point in the history
…dentities (#366)

* feat: catch Backbone error regarding deleted Identity

* test: change expected error codes accordingly

* fix: failing test due to ignored Result return type

* feat: clarify error case

* refactor: consistent Identity deletion error messages

* test: adjust error messages in tests as well

* test: adjust error messages in another test
  • Loading branch information
britsta authored Dec 12, 2024
1 parent 1a38321 commit f56c40d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/runtime/test/transport/relationships.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe("Can Create / Create Relationship", () => {

expect(canCreateRelationshipResponse.isSuccess).toBe(false);
expect(canCreateRelationshipResponse.message).toBe(
"The Identity who created the RelationshipTemplate is currently in the process of deleting itself. Thus, it is not possible to establish a Relationship to it."
"The Identity that created the RelationshipTemplate is currently in the process of deleting itself. Thus, it is not possible to establish a Relationship to it."
);
expect(canCreateRelationshipResponse.code).toBe("error.transport.relationships.activeIdentityDeletionProcessOfOwnerOfRelationshipTemplate");

Expand All @@ -184,7 +184,7 @@ describe("Can Create / Create Relationship", () => {
});

expect(createRelationshipResponse).toBeAnError(
"The Identity who created the RelationshipTemplate is currently in the process of deleting itself. Thus, it is not possible to establish a Relationship to it.",
"The Identity that created the RelationshipTemplate is currently in the process of deleting itself. Thus, it is not possible to establish a Relationship to it.",
"error.transport.relationships.activeIdentityDeletionProcessOfOwnerOfRelationshipTemplate"
);
});
Expand Down
9 changes: 8 additions & 1 deletion packages/transport/src/core/TransportCoreErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ class Relationships {
return new CoreError("error.transport.relationships.reactivationAlreadyRequested", message);
}

public deletedOwnerOfRelationshipTemplate() {
return new CoreError(
"error.transport.relationships.deletedOwnerOfRelationshipTemplate",
"The Identity that created the RelationshipTemplate has been deleted in the meantime. Thus, it is not possible to establish a Relationship to it."
);
}

public activeIdentityDeletionProcessOfOwnerOfRelationshipTemplate() {
return new CoreError(
"error.transport.relationships.activeIdentityDeletionProcessOfOwnerOfRelationshipTemplate",
"The Identity who created the RelationshipTemplate is currently in the process of deleting itself. Thus, it is not possible to establish a Relationship to it."
"The Identity that created the RelationshipTemplate is currently in the process of deleting itself. Thus, it is not possible to establish a Relationship to it."
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ export class RelationshipsController extends TransportController {

const result = await this.client.canCreateRelationship(peerAddress.toString());

if (result.isError && result.error.code === "error.platform.recordNotFound" && result.error.message.includes("Identity not found.")) {
return Result.fail(TransportCoreErrors.relationships.deletedOwnerOfRelationshipTemplate());
}

if (!result.value.canCreate) {
if (result.value.code === "error.platform.validation.relationship.relationshipToTargetAlreadyExists") {
return Result.fail(TransportCoreErrors.relationships.relationshipNotYetDecomposedByPeer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,16 @@ describe("RelationshipsController", function () {

await sender.syncEverything();

await expect(
sender.relationships.canSendRelationship({
template: loadedTemplate,
creationContent: {
mycontent: "request"
}
})
).rejects.toThrow(
"error.platform.recordNotFound (404): 'Identity not found. Make sure the ID exists and the record is not expired. If a password is required to fetch the record, make sure you passed the correct one.'"
const canSendRelationshipResult = await sender.relationships.canSendRelationship({
template: loadedTemplate,
creationContent: {
mycontent: "request"
}
});
expect(canSendRelationshipResult.isSuccess).toBe(false);
expect(canSendRelationshipResult.error.code).toBe("error.transport.relationships.deletedOwnerOfRelationshipTemplate");
expect(canSendRelationshipResult.error.message).toContain(
"The Identity that created the RelationshipTemplate has been deleted in the meantime. Thus, it is not possible to establish a Relationship to it."
);

await expect(
Expand All @@ -138,9 +139,7 @@ describe("RelationshipsController", function () {
mycontent: "request"
}
})
).rejects.toThrow(
"error.platform.recordNotFound (404): 'Identity not found. Make sure the ID exists and the record is not expired. If a password is required to fetch the record, make sure you passed the correct one.'"
);
).rejects.toThrow("error.transport.relationships.deletedOwnerOfRelationshipTemplate");
});
});

Expand Down

0 comments on commit f56c40d

Please sign in to comment.