javascript/api: Refactoring WS response handling in JS and fixing broken integration tests.
javascript/api: Refactoring WS response handling in JS and fixing broken
integration tests.

Based on recommendation in CL 2148, the code for handling WS responses in
connection.js was confusing. There was also a bug in there causing integration
tests to fail. This CL fixes the bug ( an undefined check ) and refactors
the code as well for better readability.

All JS integration tests should pass after this CL is submitted.

Change-Id: I68e4647fb899d231644072b987e9ca5e6846db88

vanadium/js,vanadium/js,vanadium/js,vanadium/js