Documentation ¶
Overview ¶
Package apierror implements a wrapper error for parsing error details from API calls. Both HTTP & gRPC status errors are supported.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMessageNotFound = errors.New("message not found")
ErrMessageNotFound is used to signal ExtractProtoMessage found no matching messages.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
// contains filtered or unexported fields
}
APIError wraps either a gRPC Status error or a HTTP googleapi.Error. It implements error and Status interfaces.
func (*APIError) Details ¶
func (a *APIError) Details() ErrDetails
Details presents the error details of the APIError.
func (*APIError) Domain ¶
Domain returns the domain in an ErrorInfo. If ErrorInfo is nil, it returns an empty string.
func (*APIError) GRPCStatus ¶
GRPCStatus extracts the underlying gRPC Status error. This method is necessary to fulfill the interface described in https://pkg.go.dev/google.golang.org/grpc/status#FromError.
func (*APIError) Metadata ¶
Metadata returns the metadata in an ErrorInfo. If ErrorInfo is nil, it returns nil.
type ErrDetails ¶
type ErrDetails struct { ErrorInfo *errdetails.ErrorInfo BadRequest *errdetails.BadRequest PreconditionFailure *errdetails.PreconditionFailure QuotaFailure *errdetails.QuotaFailure RetryInfo *errdetails.RetryInfo ResourceInfo *errdetails.ResourceInfo RequestInfo *errdetails.RequestInfo DebugInfo *errdetails.DebugInfo Help *errdetails.Help LocalizedMessage *errdetails.LocalizedMessage // Unknown stores unidentifiable error details. Unknown []interface{} }
ErrDetails holds the google/rpc/error_details.proto messages.
func (ErrDetails) ExtractProtoMessage ¶ added in v2.5.1
func (e ErrDetails) ExtractProtoMessage(v proto.Message) error
ExtractProtoMessage provides a mechanism for extracting protobuf messages from the Unknown 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 the protocol buffer type of the provided message.
func (ErrDetails) String ¶
func (e ErrDetails) String() string