refactor api error exception