@@ -274,15 +274,43 @@ To generate the signature, you must have:
274274
275275# Errors
276276
277- Errors returned by this client are often of the type [googleapi.Error].
278- These errors can be introspected for more information by using [errors.As]
279- with the richer [googleapi.Error] type. For example:
277+ Errors returned by this client are often of the type [github.com/googleapis/gax-go/v2/apierror].
278+ The [apierror.APIError] type can wrap a [google.golang.org/grpc/status.Status]
279+ if gRPC was used, or a [google.golang.org/api/googleapi.Error] if HTTP/REST was used.
280+ You might also encounter [googleapi.Error] directly from HTTP operations.
281+ These types of errors can be inspected for more information by using [errors.As]
282+ to access the specific underlying error types and retrieve detailed information,
283+ including HTTP or gRPC status codes. For example:
284+
285+ // APIErrors often wrap a googleapi.Error (for JSON and XML calls) or a status.Status (for gRPC calls)
286+ var ae *apierror.APIError
287+ if ok := errors.As(err, &ae); ok {
288+ // ae.HTTPCode() is the HTTP status code.
289+ // ae.GRPCStatus().Code() is the gRPC status code
290+ log.Printf("APIError: HTTPCode: %d, GRPCStatusCode: %s", ae.HTTPCode(), ae.GRPCStatus().Code())
291+
292+ if ae.GRPCStatus().Code() == codes.Unavailable {
293+ // ... handle gRPC unavailable ...
294+ }
295+ }
280296
297+ // This allows a user to get more information directly from googleapi.Errors (for JSON/XML calls)
281298 var e *googleapi.Error
282299 if ok := errors.As(err, &e); ok {
283- if e.Code == 409 { ... }
300+ // e.Code is the HTTP status code.
301+ // e.Message is the error message.
302+ // e.Body is the raw response body.
303+ // e.Header contains the HTTP response headers.
304+ log.Printf("HTTP Code: %d, Message: %s", e.Code, e.Message)
305+
306+ if e.Code == 409 {
307+ // ... handle conflict ...
308+ }
284309 }
285310
311+ This library may also return other errors that are not wrapped as [apierror.APIError]. For
312+ example, errors with authentication may return [cloud.google.com/go/auth.Error].
313+
286314# Retrying failed requests
287315
288316Methods in this package may retry calls that fail with transient errors.
0 commit comments