Improving error handling when fail to call api