Better api error handling