From 3d498349dd2163de9a4d6fc8faf871bf81c0c4cd Mon Sep 17 00:00:00 2001 From: Clement James Date: Mon, 30 Sep 2024 23:19:47 +0100 Subject: [PATCH] fix: code refactoring --- .../connectors/airtable/operation_update_record.go | 9 +++++---- internal/connectors/airtable/shared.go | 11 +++++------ internal/connectors/dropbox/shared.go | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/connectors/airtable/operation_update_record.go b/internal/connectors/airtable/operation_update_record.go index 57948e3..f03d7c1 100644 --- a/internal/connectors/airtable/operation_update_record.go +++ b/internal/connectors/airtable/operation_update_record.go @@ -17,6 +17,7 @@ package airtable import ( "encoding/json" "errors" + "fmt" "io" "net/http" @@ -66,7 +67,7 @@ func (c *UpdateRecordOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { return nil, errors.New("missing airtable access token") } accessToken := ctx.Auth.Extra["api-key"] - _ = sdk.InputToType[updateRecordOperationProps](ctx) + input := sdk.InputToType[updateRecordOperationProps](ctx) // data := map[string]interface{}{ // "records": map[string]interface{}{ @@ -82,7 +83,7 @@ func (c *UpdateRecordOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { // return nil, err // } - reqURL := "https://api.airtable.com/v0/meta/bases/apphx4aliBvvTd6IF/tables" + reqURL := fmt.Sprintf("https://api.airtable.com/v0/meta/bases/%s/tables", input.Bases) req, err := http.NewRequest(http.MethodGet, reqURL, nil) if err != nil { @@ -95,13 +96,13 @@ func (c *UpdateRecordOperation) Run(ctx *sdk.RunContext) (sdk.JSON, error) { client := &http.Client{} res, err := client.Do(req) if err != nil { - return err, nil + return nil, err } defer res.Body.Close() body, err := io.ReadAll(res.Body) if err != nil { - return err, nil + return nil, err } var response interface{} diff --git a/internal/connectors/airtable/shared.go b/internal/connectors/airtable/shared.go index 56df2b2..ea12948 100644 --- a/internal/connectors/airtable/shared.go +++ b/internal/connectors/airtable/shared.go @@ -238,20 +238,19 @@ func airtableRequest(accessToken, reqURL, requestType string) (interface{}, erro req.Header.Add("Accept", "application/json") req.Header.Add("Authorization", "Bearer "+accessToken) client := &http.Client{} - res, err := client.Do(req) - if err != nil { - return err, nil + res, errs := client.Do(req) + if errs != nil { + return nil, errs } defer res.Body.Close() body, err := io.ReadAll(res.Body) if err != nil { - fmt.Println("Error reading response:", err) - return nil, nil + return nil, err } var response interface{} - if errs := json.Unmarshal(body, &response); errs != nil { + if newErrs := json.Unmarshal(body, &response); newErrs != nil { return nil, errors.New("error parsing response") } diff --git a/internal/connectors/dropbox/shared.go b/internal/connectors/dropbox/shared.go index 63a3d78..768eef9 100644 --- a/internal/connectors/dropbox/shared.go +++ b/internal/connectors/dropbox/shared.go @@ -51,7 +51,7 @@ func dropBoxClient(reqURL, accessToken string, request []byte) (interface{}, err body, err := io.ReadAll(res.Body) if err != nil { - return nil, nil + return nil, err } var dropboxResponse interface{} err = json.Unmarshal(body, &dropboxResponse) @@ -74,7 +74,7 @@ func listFolderContent(reqURL, accessToken string, request []byte) (interface{}, client := &http.Client{} res, err := client.Do(req) if err != nil { - return err, nil + return nil, err } defer res.Body.Close()