* Added endLoading() function call when an error occurs.