Add error recovery to javascript if statements