For some reason everytime I run this code, I catch the "TypeError: Cannot read property \'then\' of undefined" error. I don\'t understand why. This is the code: