onError method refactoring