Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated returned error to include original error #3949

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions pkg/sources/postman/postman_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,17 @@ func (c *Client) EnumerateWorkspaces(ctx context.Context) ([]Workspace, error) {

r, err := c.getPostmanReq("https://api.getpostman.com/workspaces", nil)
if err != nil {
err = fmt.Errorf("could not get workspaces")
return nil, err
return nil, fmt.Errorf("could not get workspaces during enumeration: %w", err)
}

body, err := io.ReadAll(r.Body)
if err != nil {
err = fmt.Errorf("could not read response body for workspaces")
return nil, err
return nil, fmt.Errorf("could not read response body for workspaces during enumeration: %w", err)
}
r.Body.Close()

if err := json.Unmarshal([]byte(body), &workspacesObj); err != nil {
err = fmt.Errorf("could not unmarshal workspaces JSON")
return nil, err
return nil, fmt.Errorf("could not unmarshal workspaces JSON during enumeration: %w", err)
}

for i, workspace := range workspacesObj.Workspaces {
Expand All @@ -298,20 +295,17 @@ func (c *Client) GetWorkspace(ctx context.Context, workspaceUUID string) (Worksp
url := fmt.Sprintf(WORKSPACE_URL, workspaceUUID)
r, err := c.getPostmanReq(url, nil)
if err != nil {
err = fmt.Errorf("could not get workspace: %s", workspaceUUID)
return Workspace{}, err
return Workspace{}, fmt.Errorf("could not get workspace (%s): %w", workspaceUUID, err)
}

body, err := io.ReadAll(r.Body)
if err != nil {
err = fmt.Errorf("could not read response body for workspace: %s", workspaceUUID)
return Workspace{}, err
return Workspace{}, fmt.Errorf("could not read response body for workspace (%s): %w", workspaceUUID, err)
}
r.Body.Close()

if err := json.Unmarshal([]byte(body), &obj); err != nil {
err = fmt.Errorf("could not unmarshal workspace JSON for workspace: %s", workspaceUUID)
return Workspace{}, err
return Workspace{}, fmt.Errorf("could not unmarshal workspace JSON for workspace (%s): %w", workspaceUUID, err)
}

return obj.Workspace, nil
Expand All @@ -326,19 +320,16 @@ func (c *Client) GetEnvironmentVariables(environment_uuid string) (VariableData,
url := fmt.Sprintf(ENVIRONMENTS_URL, environment_uuid)
r, err := c.getPostmanReq(url, nil)
if err != nil {
err = fmt.Errorf("could not get env variables for environment: %s", environment_uuid)
return VariableData{}, err
return VariableData{}, fmt.Errorf("could not get env variables for environment (%s): %w", environment_uuid, err)
}

body, err := io.ReadAll(r.Body)
if err != nil {
err = fmt.Errorf("could not read env var response body for environment: %s", environment_uuid)
return VariableData{}, err
return VariableData{}, fmt.Errorf("could not read env var response body for environment (%s): %w", environment_uuid, err)
}
r.Body.Close()
if err := json.Unmarshal([]byte(body), &obj); err != nil {
err = fmt.Errorf("could not unmarshal env variables JSON for environment: %s", environment_uuid)
return VariableData{}, err
return VariableData{}, fmt.Errorf("could not unmarshal env variables JSON for environment (%s): %w", environment_uuid, err)
}

return obj.VariableData, nil
Expand All @@ -353,19 +344,16 @@ func (c *Client) GetCollection(collection_uuid string) (Collection, error) {
url := fmt.Sprintf(COLLECTIONS_URL, collection_uuid)
r, err := c.getPostmanReq(url, nil)
if err != nil {
err = fmt.Errorf("could not get collection: %s", collection_uuid)
return Collection{}, err
return Collection{}, fmt.Errorf("could not get collection (%s): %w", collection_uuid, err)
}

body, err := io.ReadAll(r.Body)
if err != nil {
err = fmt.Errorf("could not read response body for collection: %s", collection_uuid)
return Collection{}, err
return Collection{}, fmt.Errorf("could not read response body for collection (%s): %w", collection_uuid, err)
}
r.Body.Close()
if err := json.Unmarshal([]byte(body), &obj); err != nil {
err = fmt.Errorf("could not unmarshal JSON for collection: %s", collection_uuid)
return Collection{}, err
return Collection{}, fmt.Errorf("could not unmarshal JSON for collection (%s): %w", collection_uuid, err)
}

return obj.Collection, nil
Expand Down
Loading