handle errors in the API better