add missing error processing for audio (#301)
Co-authored-by: Kirill Semenchenko <smoreg@mc2soft.ru>
This commit is contained in:
committed by
GitHub
parent
a24581dce2
commit
39abb5a4be
13
audio.go
13
audio.go
@@ -43,8 +43,7 @@ func (c *Client) CreateTranscription(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request AudioRequest,
|
request AudioRequest,
|
||||||
) (response AudioResponse, err error) {
|
) (response AudioResponse, err error) {
|
||||||
response, err = c.callAudioAPI(ctx, request, "transcriptions")
|
return c.callAudioAPI(ctx, request, "transcriptions")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateTranslation — API call to translate audio into English.
|
// CreateTranslation — API call to translate audio into English.
|
||||||
@@ -52,8 +51,7 @@ func (c *Client) CreateTranslation(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request AudioRequest,
|
request AudioRequest,
|
||||||
) (response AudioResponse, err error) {
|
) (response AudioResponse, err error) {
|
||||||
response, err = c.callAudioAPI(ctx, request, "translations")
|
return c.callAudioAPI(ctx, request, "translations")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// callAudioAPI — API call to an audio endpoint.
|
// callAudioAPI — API call to an audio endpoint.
|
||||||
@@ -66,13 +64,13 @@ func (c *Client) callAudioAPI(
|
|||||||
builder := c.createFormBuilder(&formBody)
|
builder := c.createFormBuilder(&formBody)
|
||||||
|
|
||||||
if err = audioMultipartForm(request, builder); err != nil {
|
if err = audioMultipartForm(request, builder); err != nil {
|
||||||
return
|
return AudioResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
urlSuffix := fmt.Sprintf("/audio/%s", endpointSuffix)
|
urlSuffix := fmt.Sprintf("/audio/%s", endpointSuffix)
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.fullURL(urlSuffix), &formBody)
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.fullURL(urlSuffix), &formBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return AudioResponse{}, err
|
||||||
}
|
}
|
||||||
req.Header.Add("Content-Type", builder.formDataContentType())
|
req.Header.Add("Content-Type", builder.formDataContentType())
|
||||||
|
|
||||||
@@ -81,6 +79,9 @@ func (c *Client) callAudioAPI(
|
|||||||
} else {
|
} else {
|
||||||
err = c.sendRequest(req, &response.Text)
|
err = c.sendRequest(req, &response.Text)
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
return AudioResponse{}, err
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user