adding error handling for api response