refactor the api errors