Error handling for javascript