Skip to content

Commit

Permalink
add missing error processing for audio (sashabaranov#301)
Browse files Browse the repository at this point in the history
Co-authored-by: Kirill Semenchenko <smoreg@mc2soft.ru>
  • Loading branch information
smoreg and Kirill Semenchenko authored May 4, 2023
1 parent a24581d commit 39abb5a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,15 @@ 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.
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.
Expand All @@ -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())

Expand All @@ -81,6 +79,9 @@ func (c *Client) callAudioAPI(
} else {
err = c.sendRequest(req, &response.Text)
}
if err != nil {
return AudioResponse{}, err
}
return
}

Expand Down

0 comments on commit 39abb5a

Please sign in to comment.