add missing error processing for audio (#301)

Co-authored-by: Kirill Semenchenko <smoreg@mc2soft.ru>
This commit is contained in:
Semenchenko Kirill
2023-05-05 00:30:14 +06:00
committed by GitHub
parent a24581dce2
commit 39abb5a4be

View File

@@ -43,8 +43,7 @@ func (c *Client) CreateTranscription(
ctx context.Context,
request AudioRequest,
) (response AudioResponse, err error) {
response, err = c.callAudioAPI(ctx, request, "transcriptions")
return
return c.callAudioAPI(ctx, request, "transcriptions")
}
// CreateTranslation — API call to translate audio into English.
@@ -52,8 +51,7 @@ func (c *Client) CreateTranslation(
ctx context.Context,
request AudioRequest,
) (response AudioResponse, err error) {
response, err = c.callAudioAPI(ctx, request, "translations")
return
return c.callAudioAPI(ctx, request, "translations")
}
// callAudioAPI — API call to an audio endpoint.
@@ -66,13 +64,13 @@ func (c *Client) callAudioAPI(
builder := c.createFormBuilder(&formBody)
if err = audioMultipartForm(request, builder); err != nil {
return
return AudioResponse{}, err
}
urlSuffix := fmt.Sprintf("/audio/%s", endpointSuffix)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.fullURL(urlSuffix), &formBody)
if err != nil {
return
return AudioResponse{}, err
}
req.Header.Add("Content-Type", builder.formDataContentType())
@@ -81,6 +79,9 @@ func (c *Client) callAudioAPI(
} else {
err = c.sendRequest(req, &response.Text)
}
if err != nil {
return AudioResponse{}, err
}
return
}