Skip to content

Commit bfeae65

Browse files
committed
Fix error seen in dev
1 parent e6053fe commit bfeae65

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/api/role/role.service.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,16 @@ describe('RoleService', () => {
390390
).rejects.toThrow(NotFoundException);
391391
});
392392

393-
it('should throw ConflictException if assignment already exists', async () => {
393+
it('should ignore duplicate assignment if already exists', async () => {
394394
mockPrisma.role.count.mockResolvedValue(1);
395395
mockPrisma.roleAssignment.create.mockRejectedValue({ code: 'P2002' });
396396

397397
await expect(
398398
service.assignRoleToSubject(roleId, subjectId, operatorId),
399-
).rejects.toThrow(ConflictException);
399+
).resolves.toBeUndefined();
400+
expect(mockLogger.warn).toHaveBeenCalledWith(
401+
`Attempt to assign role ${roleId} to subject ${subjectId} which already exists. Ignoring duplicate.`,
402+
);
400403
});
401404
});
402405

src/api/role/role.service.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -376,18 +376,15 @@ export class RoleService {
376376
} catch (error) {
377377
if (error.code === Constants.prismaUniqueConflictcode) {
378378
this.logger.warn(
379-
`Attempt to assign role ${roleId} to subject ${subjectId} which already exists.`,
379+
`Attempt to assign role ${roleId} to subject ${subjectId} which already exists. Ignoring duplicate.`,
380380
);
381-
throw new ConflictException(
382-
`Role ${roleId} is already assigned to subject ${subjectId}.`,
383-
);
384-
} else {
385-
this.logger.error(
386-
`Failed to assign role ${roleId} to subject ${subjectId}: ${error.message}`,
387-
error.stack,
388-
);
389-
throw error;
381+
return;
390382
}
383+
this.logger.error(
384+
`Failed to assign role ${roleId} to subject ${subjectId}: ${error.message}`,
385+
error.stack,
386+
);
387+
throw error;
391388
}
392389
}
393390

0 commit comments

Comments
 (0)