Skip to content
Advertisement

Validate data in Dynamodb is only working through if data is present

this is a rather easy and silly question but I can’t seem to understand the problem at hand.

I am trying to create a register page where user could enter thier email, if their email is present, then the the function will put items into the database, if not, it will return “email is already present.

JavaScript

EDIT:-

JavaScript

My problem is , when a user enters an email that is already present, the function will return “email already exists”, but when a user enters a unique email, the if statement throws an “list index out range”. I know exactly what this error means, but what i don’t under is that what does the function renders this error?! I have 10 entries in my dynamodb and when i enter 10 instead of 0, I still get the same error.

Help is greatly appreciated.

Advertisement

Answer

You should first check if items list is empty or not. As you are entering unique email, items will be an empty list.

If list does not have any item and you check for 0th index it will throw list index out of range exception.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement