Implement error handling and disconnecting client  on errors