refactor common errors to helper