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

feat(gengapic): raise Operation errors from diregapic #1323

Merged
merged 7 commits into from
May 9, 2023

Conversation

quartzmo
Copy link
Member

@quartzmo quartzmo commented May 8, 2023

closes: #1320

Partial diff after running bazelisk build //google/cloud/compute/v1:compute_go_gapic locally:

diff --git a/compute/apiv1/operations.go b/compute/apiv1/operations.go
index 0f77e7e2a0..d916441204 100755
--- a/compute/apiv1/operations.go
+++ b/compute/apiv1/operations.go
@@ -18,10 +18,13 @@ package compute

 import (
        "context"
+       "fmt"
        "time"

        computepb "cloud.google.com/go/compute/apiv1/computepb"
        gax "github.com/googleapis/gax-go/v2"
+       "github.com/googleapis/gax-go/v2/apierror"
+       "google.golang.org/api/googleapi"
 )

 // Operation represents a long-running operation for this API.
@@ -87,6 +90,14 @@ func (h *regionOperationsHandle) Poll(ctx context.Context, opts ...gax.CallOptio
                return err
        }
        h.proto = resp
+       if resp.HttpErrorStatusCode != nil && (resp.GetHttpErrorStatusCode() < 200 || resp.GetHttpErrorStatusCode() > 299) {
+               aErr := &googleapi.Error{
+                       Code:    int(resp.GetHttpErrorStatusCode()),
+                       Message: fmt.Sprintf("%s: %v", resp.GetHttpErrorMessage(), resp.GetError()),
+               }
+               err, _ := apierror.FromError(aErr)
+               return err
+       }
        return nil
 }
...

@quartzmo quartzmo force-pushed the diregapic-operations-error branch from 651fb89 to 6fc9e65 Compare May 8, 2023 22:39
@quartzmo quartzmo marked this pull request as ready for review May 9, 2023 15:45
@quartzmo quartzmo requested review from a team as code owners May 9, 2023 15:45
internal/gengapic/custom_operation.go Outdated Show resolved Hide resolved
internal/gengapic/custom_operation.go Outdated Show resolved Hide resolved
internal/gengapic/custom_operation.go Outdated Show resolved Hide resolved
internal/gengapic/custom_operation.go Outdated Show resolved Hide resolved
internal/gengapic/custom_operation.go Outdated Show resolved Hide resolved
internal/gengapic/custom_operation.go Outdated Show resolved Hide resolved
@quartzmo quartzmo merged commit 66d43c6 into googleapis:main May 9, 2023
7 checks passed
@quartzmo quartzmo deleted the diregapic-operations-error branch May 9, 2023 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

diregapic: errors that appear in the Operation type should be returned by Poll
2 participants