Skip to content

Commit

Permalink
add try/catch error handling to dynamodb query
Browse files Browse the repository at this point in the history
  • Loading branch information
jdub233 committed Feb 7, 2024
1 parent 0089c79 commit a244cb2
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/authorizeRequest/authorizeRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,22 @@ async function authorizeRequest(userRequest, siteRule, networkRanges) {
// Get the rules for the group.
// Need to skip this for the entire-bu-community group, since it is not in the database.
// to avoid INFO Failed to find the group in DynamoDB for group: entire-bu-community
const { Item } = await dynamoDb.get({
TableName: tableName,
Key: { PK: siteAndGroupKey },
});
let response;
try {
response = await dynamoDb.get({
TableName: tableName,
Key: { PK: siteAndGroupKey },
});
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
}

const { Item } = response;

if (Item == null) {
// If the group rules are not found, log the error then deny access.
// eslint-disable-next-line no-console
console.log('Failed to find the group in DynamoDB for group: ', groupName);
return false;
}
Expand Down

0 comments on commit a244cb2

Please sign in to comment.