Skip to content

Commit fccab02

Browse files
authored
Handling the conflict case where email has been already taken in AWS (#2271)
* Fix: change env variables from obj to string This resolves the error faced in staging for the discord command developed by me /grant-aws-access, we were facing this issue when running this in stgaging, this is becuase in the node-config the values were being set as obj with name field as the actual value * lint-fix * removing console log statement * removing the extra log * handling conflict case, where user with email already exists in AWS
1 parent aaa2de4 commit fccab02

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

controllers/awsAccess.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ export const addUserToAWSGroup = async (req, res) => {
2121
if (awsUserId === null){
2222
// We need to create the user in AWS before and then fetch its Id
2323
userCreationResponse = await createUser(userInfoData.user.username, userInfoData.user.email);
24+
25+
if (userCreationResponse.conflict){
26+
return res.status(400).json({
27+
error: `Username or Email is already being used, please use another email / username for creating account in AWS`
28+
})
29+
}
2430
awsUserId = userCreationResponse.UserId;
2531
}
2632

utils/awsFunctions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ import {
6767
const command = new CreateUserCommand(params);
6868
return (await client.send(command));
6969
} catch (error) {
70-
console.error(`The error from create user ${error}`);
70+
if (error.__type === 'ConflictException'){
71+
return { conflict: true };
72+
}
73+
7174
throw new Error(`Failed to create user: ${error instanceof Error ? error.message : String(error)}`);
7275
}
7376
};
@@ -93,7 +96,6 @@ export const addUserToGroup = async (groupId: string, awsUserId: string): Promis
9396
const command = new CreateGroupMembershipCommand(params);
9497
return (await client.send(command));
9598
} catch (error) {
96-
console.error("Error adding user to group:", error);
9799
if (error.__type === 'ConflictException'){
98100
return { conflict: true };
99101
}

0 commit comments

Comments
 (0)