add socket error listener to prevent exception

if there's no listener an exception is thrown (default node EventEmitter
behavior)
catch malformed JSON exceptions

JSON.parse is known to throw exceptions, it's necessary to catch them