dealing with errors on javascript