deepgram/deepgram-go-sdk

Can't handle errors with LiveTranscription

Closed this issue · 5 comments

What is the current behavior?

Currently, the LiveTranscription function claims it returns errors, but then a call to log.Fatal inside the code ends execution before the return can ever happen.

Steps to reproduce

Connect with options that cause an error (Like language: en-NZ + model: meeting

Expected behavior

I expect the error to be returned by the function, so I can handle it in scope.

This is an easy enough fix:

Current Function:

func (dg *Client) LiveTranscription(options LiveTranscriptionOptions) (*websocket.Conn, *http.Response, error) {
	query, _ := query.Values(options)
	u := url.URL{Scheme: "wss", Host: dg.Host, Path: "/v1/listen", RawQuery: query.Encode()}
	log.Printf("connecting to %s", u.String())

	header := http.Header{
		"Host":          []string{dg.Host},
		"Authorization": []string{"token " + dg.ApiKey},
		"X-DG-Agent":    []string{dgAgent},
	}

	c, resp, err := websocket.DefaultDialer.Dial(u.String(), header)

	if err != nil {
		log.Printf("handshake failed with status %s", resp.Status)
		log.Fatal("dial:", err)
	}
	return c, resp, nil
}

Fixed Function:

func (dg *Client) LiveTranscription(options LiveTranscriptionOptions) (*websocket.Conn, *http.Response, error) {
	query, _ := query.Values(options)
	u := url.URL{Scheme: "wss", Host: dg.Host, Path: "/v1/listen", RawQuery: query.Encode()}
	log.Printf("connecting to %s", u.String())

	header := http.Header{
		"Host":          []string{dg.Host},
		"Authorization": []string{"token " + dg.ApiKey},
		"X-DG-Agent":    []string{dgAgent},
	}

	return  websocket.DefaultDialer.Dial(u.String(), header)
}

@cchunn-veritone, would you like to make a PR to fix this?

@dvonthenen 👋 I'm curious if you'll be handling this issue in our upcoming V1 Major Release of the GoSDK?

This should be fixed in this PR:
#88

Addressed in PR #108. Closing because PR was merged.