Skip to content

Commit

Permalink
add try catch to handle for getUserData
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashchoudhary07 committed Aug 25, 2023
1 parent 9191dcb commit ac5884d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
12 changes: 7 additions & 5 deletions controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ const googleAuthCallback = (

let rCalUiUrl = new URL(config.get('services.rCalUi.baseUrl'));

try {
rCalUiUrl = new URL(redirectURL);
} catch (error) {
logger.error('Invalid redirect URL provided');
logger.error(error);
if (redirectURL) {
try {
rCalUiUrl = new URL(redirectURL);
} catch (error) {
logger.error('Invalid redirect URL provided');
logger.error(error);
}
}

try {
Expand Down
37 changes: 21 additions & 16 deletions services/authService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,29 @@ const decodeAuthToken = (token: string): any => {
*/
const getUserData = async (
email: string
): Promise<Users & { calendarId: number }> => {
const user = await prisma.users.findUniqueOrThrow({
where: {
email,
},
include: {
Calendar: {
where: {
isDeleted: false,
isPrimary: true,
},
select: {
id: true,
): Promise<(Users & { calendarId: number }) | undefined> => {
try {
const user = await prisma.users.findUniqueOrThrow({
where: {
email,
},
include: {
Calendar: {
where: {
isDeleted: false,
isPrimary: true,
},
select: {
id: true,
},
},
},
},
});
return { ...user, calendarId: user.Calendar[0].id };
});
return { ...user, calendarId: user.Calendar[0].id };
} catch (error) {
logger.error('Could not find user', error);
return undefined;
}
};

/**
Expand Down

0 comments on commit ac5884d

Please sign in to comment.