refactor error handling for hapi