move error handling logics into errorhandlers.js