From 39abb5a4be4a64a745aeb851a8ce647c8f1250f7 Mon Sep 17 00:00:00 2001 From: Semenchenko Kirill Date: Fri, 5 May 2023 00:30:14 +0600 Subject: [PATCH] add missing error processing for audio (#301) Co-authored-by: Kirill Semenchenko --- audio.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/audio.go b/audio.go index 46c3711..d22daf9 100644 --- a/audio.go +++ b/audio.go @@ -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 }