apierr

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CodeName

func CodeName(c codes.Code) string

CodeName returns the google.rpc.Code enum name (e.g. NOT_FOUND).

func HTTPFromCode

func HTTPFromCode(c codes.Code) int

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 Aborted

func Aborted(format string, args ...any) *Error

func AlreadyExists

func AlreadyExists(format string, args ...any) *Error

func FailedPrecondition

func FailedPrecondition(format string, args ...any) *Error

func From

func From(err error) *Error

From converts any error into an *Error.

func Internal

func Internal(format string, args ...any) *Error

func InvalidArgument

func InvalidArgument(format string, args ...any) *Error

func New

func New(code codes.Code, format string, args ...any) *Error

New creates an error with a formatted message.

func NotFound

func NotFound(format string, args ...any) *Error

func PermissionDenied

func PermissionDenied(format string, args ...any) *Error

func Unauthenticated

func Unauthenticated(format string, args ...any) *Error

func Unimplemented

func Unimplemented(format string, args ...any) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) GRPCStatus

func (e *Error) GRPCStatus() *status.Status

GRPCStatus implements the interface used by grpc/status.FromError.

func (*Error) HTTP

func (e *Error) HTTP() int

HTTP returns the HTTP status for the error.

func (*Error) JSON

func (e *Error) JSON() []byte

JSON renders the REST error envelope.

func (*Error) WithHTTP

func (e *Error) WithHTTP(code int) *Error

WithHTTP overrides the HTTP status and returns e.

func (*Error) WithLegacy

func (e *Error) WithLegacy(reason string) *Error

WithLegacy sets the legacy errors[].reason and returns e.

func (*Error) WithReason

func (e *Error) WithReason(domain, reason string) *Error

WithReason sets the ErrorInfo reason/domain and returns e.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL