Skip to content

Commit 39abb5a

Browse files
smoregKirill Semenchenko
andauthored
add missing error processing for audio (#301)
Co-authored-by: Kirill Semenchenko <[email protected]>
1 parent a24581d commit 39abb5a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

audio.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,15 @@ func (c *Client) CreateTranscription(
4343
ctx context.Context,
4444
request AudioRequest,
4545
) (response AudioResponse, err error) {
46-
response, err = c.callAudioAPI(ctx, request, "transcriptions")
47-
return
46+
return c.callAudioAPI(ctx, request, "transcriptions")
4847
}
4948

5049
// CreateTranslation — API call to translate audio into English.
5150
func (c *Client) CreateTranslation(
5251
ctx context.Context,
5352
request AudioRequest,
5453
) (response AudioResponse, err error) {
55-
response, err = c.callAudioAPI(ctx, request, "translations")
56-
return
54+
return c.callAudioAPI(ctx, request, "translations")
5755
}
5856

5957
// callAudioAPI — API call to an audio endpoint.
@@ -66,13 +64,13 @@ func (c *Client) callAudioAPI(
6664
builder := c.createFormBuilder(&formBody)
6765

6866
if err = audioMultipartForm(request, builder); err != nil {
69-
return
67+
return AudioResponse{}, err
7068
}
7169

7270
urlSuffix := fmt.Sprintf("/audio/%s", endpointSuffix)
7371
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.fullURL(urlSuffix), &formBody)
7472
if err != nil {
75-
return
73+
return AudioResponse{}, err
7674
}
7775
req.Header.Add("Content-Type", builder.formDataContentType())
7876

@@ -81,6 +79,9 @@ func (c *Client) callAudioAPI(
8179
} else {
8280
err = c.sendRequest(req, &response.Text)
8381
}
82+
if err != nil {
83+
return AudioResponse{}, err
84+
}
8485
return
8586
}
8687

0 commit comments

Comments
 (0)