Documentation
¶
Overview ¶
Package apierr models GCP API errors and renders them as the JSON error envelope used by REST APIs and as google.rpc.Status for gRPC (FR-CORE-025).
Index ¶
- func CodeName(c codes.Code) string
- func HTTPFromCode(c codes.Code) int
- func Write(w http.ResponseWriter, err error)
- type Error
- func Aborted(format string, args ...any) *Error
- func AlreadyExists(format string, args ...any) *Error
- func FailedPrecondition(format string, args ...any) *Error
- func From(err error) *Error
- func Internal(format string, args ...any) *Error
- func InvalidArgument(format string, args ...any) *Error
- func New(code codes.Code, format string, args ...any) *Error
- func NotFound(format string, args ...any) *Error
- func PermissionDenied(format string, args ...any) *Error
- func Unauthenticated(format string, args ...any) *Error
- func Unimplemented(format string, args ...any) *Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTTPFromCode ¶
HTTPFromCode maps a canonical code to an HTTP status per google.rpc.Code docs.
func Write ¶
func Write(w http.ResponseWriter, err error)
Write writes err as a REST JSON error response.
Types ¶
type Error ¶
type Error struct {
Code codes.Code
Message string
// Reason is the ErrorInfo reason (UPPER_SNAKE), e.g. "RESOURCE_NOT_FOUND".
Reason string
// Domain is the ErrorInfo domain, e.g. "storage.googleapis.com".
Domain string
// LegacyReason is the v1 "errors[].reason" value (lowerCamel), e.g. "notFound".
LegacyReason string
// HTTPStatus overrides the status derived from Code (e.g. 412 for GCS preconditions).
HTTPStatus int
Metadata map[string]string
}
Error is a GCP-shaped API error.
func AlreadyExists ¶
func FailedPrecondition ¶
func InvalidArgument ¶
func PermissionDenied ¶
func Unauthenticated ¶
func Unimplemented ¶
func (*Error) GRPCStatus ¶
GRPCStatus implements the interface used by grpc/status.FromError.
func (*Error) WithLegacy ¶
WithLegacy sets the legacy errors[].reason and returns e.
func (*Error) WithReason ¶
WithReason sets the ErrorInfo reason/domain and returns e.