refactor error handling mechanism
Merge branch 'henryleu'