handling empty responses and errors