make ajax error handling more reliable