Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Runtime error for attempt to establish Relationships to deleted Identities #366

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
Loading