func websocketDialWithErrors(dialer WebsocketDialer, urlStr string, requestHeader http.Header) (base.Stream, error) {
	c, resp, err := dialer.Dial(urlStr, requestHeader)
	if err != nil {
		if err == websocket.ErrBadHandshake {
			// If ErrBadHandshake is returned, a non-nil response
			// is returned so the client can react to auth errors
			// (for example).
			//
			// The problem here is that there is a response, but the response
			// body is truncated to 1024 bytes for debugging information, not
			// for a true response. While this may work for small bodies, it
			// isn't guaranteed to work for all messages.
			defer resp.Body.Close()
			body, readErr := ioutil.ReadAll(resp.Body)
			if readErr != nil {
				return nil, err
			}
			if resp.Header.Get("Content-Type") == "application/json" {
				var result params.ErrorResult
				jsonErr := json.Unmarshal(body, &result)
				if jsonErr != nil {
					return nil, errors.Annotate(jsonErr, "reading error response")
				}
				return nil, result.Error
			}

			err = errors.Errorf(
				"%s (%s)",
				strings.TrimSpace(string(body)),
				http.StatusText(resp.StatusCode),
			)
		}
		return nil, err
	}
	result := DeadlineStream{Conn: c, Timeout: websocketTimeout}
	return &result, nil
}
// websocketDialWithErrors dials the websocket and extracts any error
// from the response if there's a handshake error setting up the
// socket. Any other errors are returned normally.
websocketDialWithErrors dials the websocket and extracts any error
from the response if there's a handshake error setting up the
socket. Any other errors are returned normally.
// websocketDialWithErrors dials the websocket and extracts any error // from the response if there ' s a handshake error setting up the // socket . Any other errors are returned normally .
func websocketDialWithErrors(dialer WebsocketDialer, urlStr string, requestHeader http.Header) (base.Stream, error) {
	c, resp, err := dialer.Dial(urlStr, requestHeader)
	if err != nil {
		if err == websocket.ErrBadHandshake {
			 The problem here is that there is a response, but the response
			 body is truncated to 1024 bytes for debugging information, not
			 for a true response. While this may work for small bodies, it
			 isn't guaranteed to work for all messages.
			defer resp.Body.Close()
			body, readErr := ioutil.ReadAll(resp.Body)
			if readErr != nil {
				return nil, err
			}
			if resp.Header.Get("Content-Type") == "application/json" {
				var result params.ErrorResult
				jsonErr := json.Unmarshal(body, &result)
				if jsonErr != nil {
					return nil, errors.Annotate(jsonErr, "reading error response")
				}
				return nil, result.Error
			}
			err = errors.Errorf(
				"%s (%s)",
				strings.TrimSpace(string(body)),
				http.StatusText(resp.StatusCode),
			)
		}
		return nil, err
	}
	result := DeadlineStream{Conn: c, Timeout: websocketTimeout}
	return &result, nil
}
func websocketDialWithErrors ( dialer WebsocketDialer , urlStr string , requestHeader http . Header ) ( base . Stream , error ) { c , resp , err := dialer . Dial ( urlStr , requestHeader ) if err != nil { if err == websocket . ErrBadHandshake { defer resp . Body . Close ( ) body , readErr := ioutil . ReadAll ( resp . Body ) if readErr != nil { return nil , err } if resp . Header . Get ( " " ) == " " { var result params . ErrorResult jsonErr := json . Unmarshal ( body , & result ) if jsonErr != nil { return nil , errors . Annotate ( jsonErr , " " ) } return nil , result . Error } err = errors . Errorf ( " " , strings . TrimSpace ( string ( body ) ) , http . StatusText ( resp . StatusCode ) , ) } return nil , err } result := DeadlineStream { Conn : c , Timeout : websocketTimeout } return & result , nil }
websocketDialWithErrors dials the websocket and extracts any error
from the response if there's a handshake error setting up the
socket.
websocketDialWithErrors dials the websocket and extracts any error from the response if there ' s a handshake error setting up the socket .
// If ErrBadHandshake is returned, a non-nil response // is returned so the client can react to auth errors // (for example). // // The problem here is that there is a response, but the response // body is truncated to 1024 bytes for debugging information, not // for a true response. While this may work for small bodies, it // isn't guaranteed to work for all messages.