Movatterモバイル変換


[0]ホーム

URL:


apierror

package
v2.16.0Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2025 License:BSD-3-ClauseImports:11Imported by:108

Details

Repository

github.com/googleapis/gax-go

Links

Documentation

Overview

Package apierror implements a wrapper error for parsing error details fromAPI calls. Both HTTP & gRPC status errors are supported.

For examples of how to useAPIError with client libraries please reference[Inspecting errors](https://pkg.go.dev/cloud.google.com/go#hdr-Inspecting_errors)in the client library documentation.

Index

Constants

This section is empty.

Variables

View Source
var ErrMessageNotFound =errors.New("message not found")

ErrMessageNotFound is used to signal ExtractProtoMessage found no matching messages.

Functions

This section is empty.

Types

typeAPIError

type APIError struct {// contains filtered or unexported fields}

APIError wraps either a gRPC Status error or a HTTP googleapi.Error. Itimplements error and Status interfaces.

funcFromError

func FromError(errerror) (*APIError,bool)

FromError parses a Status error or a googleapi.Error and builds anAPIError, wrapping the provided error in the new APIError. Itreturns false if neither Status nor googleapi.Error can be parsed.

funcParseErroradded inv2.7.0

func ParseError(errerror, wrapbool) (*APIError,bool)

ParseError parses a Status error or a googleapi.Error and builds anAPIError. If wrap is true, it wraps the error in the new APIError.It returns false if neither Status nor googleapi.Error can be parsed.

func (*APIError)Details

func (a *APIError) Details()ErrDetails

Details presents the error details of the APIError.

func (*APIError)Domain

func (a *APIError) Domain()string

Domain returns the domain in an ErrorInfo.If ErrorInfo is nil, it returns an empty string.

func (*APIError)Error

func (a *APIError) Error()string

Error returns a readable representation of the APIError.

func (*APIError)GRPCStatus

func (a *APIError) GRPCStatus() *status.Status

GRPCStatus extracts the underlying gRPC Status error.This method is necessary to fulfill the interfacedescribed inhttps://pkg.go.dev/google.golang.org/grpc/status#FromError.

For errors that originated as an HTTP-based googleapi.Error, GRPCStatus()returns a status that attempts to map from the original HTTP code to anequivalent gRPC status code. For use cases where you want to avoid thisbehavior, error unwrapping can be used.

func (*APIError)HTTPCodeadded inv2.9.0

func (a *APIError) HTTPCode()int

HTTPCode returns the underlying HTTP response status code. This method returns`-1` if the underlying error is agoogle.golang.org/grpc/status.Status. Tocheck gRPC error codes usegoogle.golang.org/grpc/status.Code.

func (*APIError)Metadata

func (a *APIError) Metadata() map[string]string

Metadata returns the metadata in an ErrorInfo.If ErrorInfo is nil, it returns nil.

func (*APIError)Reason

func (a *APIError) Reason()string

Reason returns the reason in an ErrorInfo.If ErrorInfo is nil, it returns an empty string.

func (*APIError)Unwrap

func (a *APIError) Unwrap()error

Unwrap extracts the original error.

typeErrDetails

type ErrDetails struct {ErrorInfo           *errdetails.ErrorInfoBadRequest          *errdetails.BadRequestPreconditionFailure *errdetails.PreconditionFailureQuotaFailure        *errdetails.QuotaFailureRetryInfo           *errdetails.RetryInfoResourceInfo        *errdetails.ResourceInfoRequestInfo         *errdetails.RequestInfoDebugInfo           *errdetails.DebugInfoHelp                *errdetails.HelpLocalizedMessage    *errdetails.LocalizedMessage// Unknown stores unidentifiable error details.Unknown []interface{}}

ErrDetails holds the google/rpc/error_details.proto messages.

func (ErrDetails)ExtractProtoMessageadded inv2.5.1

func (eErrDetails) ExtractProtoMessage(vproto.Message)error

ExtractProtoMessage provides a mechanism for extracting protobuf messages from theUnknown error details. If ExtractProtoMessage finds an unknown message of the same type,the content of the message is copied to the provided message.

ExtractProtoMessage will return ErrMessageNotFound if there are no message matching theprotocol buffer type of the provided message.

func (ErrDetails)String

func (eErrDetails) String()string

Source Files

View all Source files

Directories

PathSynopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp