Skip to content

Commit

Permalink
fix: code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymesC committed Sep 30, 2024
1 parent 589617c commit 3d49834
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
9 changes: 5 additions & 4 deletions internal/connectors/airtable/operation_update_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package airtable
import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"

Expand Down Expand Up @@ -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{}{
Expand All @@ -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 {
Expand All @@ -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{}
Expand Down
11 changes: 5 additions & 6 deletions internal/connectors/airtable/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
4 changes: 2 additions & 2 deletions internal/connectors/dropbox/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand Down

0 comments on commit 3d49834

Please sign in to comment.