refactored the logic in the ajax error handlers