Improved XMLHttpRequest error handling.