errtag

package
v0.0.0-...-8495beb Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: MPL-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package errtag facilitates tagging error chains with distinct categories. The whole point of tagging errors with categories is to facilitate easier casting from errors to HTTP status codes at the transport layer. It also means you don't need to use explicit, manually defined custom errors for common things such as `sql.ErrNoRows`. You can decorate an error with metadata and tag it as a "not found" kind of error and at the transport layer, handle all errors with a unified error handler that can automatically set the HTTP status code.

An error tag is any type which satisfies the interface `Tag() string`. Included in the library is a set of commonly used kinds of problem that can occur in most applications. These are based on gRPC status codes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tag

func Tag(err error) errorTag

Tag extracts the error tag of an error chain. If there's no tag, returns nil.

func Wrap

func Wrap(parent error, et errorTag) error

Wrap wraps an error and gives it a distinct tag.

Types

type AlreadyExists

type AlreadyExists struct{} // The entity that a client attempted to create already exists.

func (AlreadyExists) Tag

func (AlreadyExists) Tag() string

type Cancelled

type Cancelled struct{} // The operation was cancelled, typically by the caller.

func (Cancelled) Tag

func (Cancelled) Tag() string

type Internal

type Internal struct{} // Internal errors. This means that some invariants expected by the underlying system have been broken. This error code is reserved for serious errors.

func (Internal) Tag

func (Internal) Tag() string

type InvalidArgument

type InvalidArgument struct{} // The client specified an invalid argument.

func (InvalidArgument) Tag

func (InvalidArgument) Tag() string

type NotFound

type NotFound struct{} // Some requested entity was not found.

func (NotFound) Tag

func (NotFound) Tag() string

type PermissionDenied

type PermissionDenied struct{} // The caller does not have permission to execute the specified operation.

func (PermissionDenied) Tag

func (PermissionDenied) Tag() string

type Unauthenticated

type Unauthenticated struct{} // The request does not have valid authentication credentials for the operation.

func (Unauthenticated) Tag

func (Unauthenticated) Tag() string

Jump to

Keyboard shortcuts

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