add error handling while api is invalid