add try catch for TypeError