catch error when we get from the network less data than we expect

On failure of the network we may come less data than we expect. When we are reading more bytes from the buffer may raise uncaught exception. This commit is converted an exception to error event.