Skip to content

Commit

Permalink
fix(wf-error-handling): generate end user w/ business errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alonp99 committed Sep 22, 2024
1 parent 5dae083 commit 3ae8e1d
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions services/workflows-service/src/workflow/workflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1699,31 +1699,42 @@ export class WorkflowService {
entityId: string;
position?: BusinessPosition;
}) {
if (entityData && entityType === 'business') {
return (
await this.endUserService.createWithBusiness(
{
endUser: {
...entityData,
isContactPerson: true,
},
business: {
companyName: '',
...workflowRuntimeData.context.entity.data,
projectId: currentProjectId,
},
position,
},
currentProjectId,
entityId,
)
).id;
if (!entityData) {
throw new BadRequestException('Entity data is missing. Please provide end user data.');
}

throw new Error(
`Invalid entity type or payload for child workflow creation for entity: ${entityType} with context:`,
workflowRuntimeData.context.entity,
);
if (entityType !== 'business') {
throw new BadRequestException(`Invalid entity type: ${entityType}. Expected 'business'.`);
}

try {
const result = await this.endUserService.createWithBusiness(
{
endUser: {
...entityData,
isContactPerson: true,
},
business: {
companyName: '',
...workflowRuntimeData.context.entity.data,
projectId: currentProjectId,
},
position,
},
currentProjectId,
entityId,
);

return result.id;
} catch (error) {
this.logger.error('Failed to create end user with business', {
error,
entityType,
entityId,
currentProjectId,
});
throw new Error('Failed to create end user with business. Please try again later.');
}
}

private async __persistDocumentPagesFiles(
Expand Down

0 comments on commit 3ae8e1d

Please sign in to comment.