catch error and display error message if ajax call to API fails