refactoring errorhandlers.js