keyshade
keyshade copied to clipboard
API: Error while inviting user to workspace
Describe the bug
When we try to invite a user to a workspace, and we try to assign them a role ID that doesn't exist, instead of returning a 404 with proper error message, the API throws a 500 error.
To Reproduce Steps to reproduce the behavior:
- Create a workspace
- Try to invite another user to the workspace and in
roleIds
array, supply an ID that doesn't exist - Encounter the error
Expected behavior
If a workspace role provided in the roleIds
array doesn't exist, we want to return a 404 specifying that the particular role doesn't exist.
Screenshots
- Postman request:
- Response:
- Server logs:
api:dev: [ERROR] 2024-07-30 14:21:38 -
api:dev: Invalid `this.prisma.workspaceMember.create()` invocation in
api:dev: /home/raj/oss/keyshade.xyz/keyshade-xyz/apps/api/src/workspace/service/workspace.service.ts:983:60
api:dev:
api:dev: 980 }
api:dev: 981
api:dev: 982 // Create the workspace membership
api:dev: → 983 const createMembership = this.prisma.workspaceMember.create(
api:dev: An operation failed because it depends on one or more records that were required but not found. No 'WorkspaceRole' record(s) (needed to inline the relation on 'WorkspaceMemberRoleAssociation' record(s)) was found for a nested connect on one-to-many relation 'WorkspaceMemberRoleAssociationToWorkspaceRole'.
Desktop (please complete the following information):
- OS: Ubuntu
- Browser: Postman
- Version: 2.3.0
Additional context
We also doubt that the same error will be present in Update member role
endpoint aswell.