Skip to content

Commit

Permalink
fix: deal with possibly undefined request content
Browse files Browse the repository at this point in the history
  • Loading branch information
slavistan committed Dec 20, 2023
1 parent 32c04fd commit 34d3d74
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/modules/coreHttpApi/controllers/AttributesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export class AttributesController extends BaseController {
/* We left 'owner' and '@type' optional in the openapi spec for
* backwards compatibility. If set, they have to be removed here or the runtime
* use case will throw an error. */
if (typeof request.content.owner !== "undefined") delete request.content.owner;
if (request.content["@type"] === "IdentityAttribute") delete request.content["@type"];
if (typeof request.content?.owner !== "undefined") delete request.content.owner;
if (request.content?.["@type"] === "IdentityAttribute") delete request.content["@type"];

const result = await this.consumptionServices.attributes.createIdentityAttribute(request);
return this.created(result);
Expand Down Expand Up @@ -50,15 +50,14 @@ export class AttributesController extends BaseController {
return this.created(result);
}

// TODO: delete succeedAttribute?
@POST
@Path("/SucceedAttribute")
@Accept("application/json")
public async succeedAttribute(request: any): Promise<Return.NewResource<Envelope>> {
const predecessorResult = await this.consumptionServices.attributes.getAttribute(request.predecessorId);
const predecessor = predecessorResult.value;
let result: any;
if (predecessor["content"]["@type"] === "IdentityAttribute") {
if (predecessor.content["@type"] === "IdentityAttribute") {
result = await this.consumptionServices.attributes.succeedIdentityAttribute(request);
} else {
result = await this.consumptionServices.attributes.succeedRelationshipAttributeAndNotifyPeer(request);
Expand Down

0 comments on commit 34d3d74

Please sign in to comment.