Error handling while making AJAX requests in JavaScript