errs

package
v0.0.0-...-16ef530 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package errs provides types and support related to web error functionality.

Index

Constants

This section is empty.

Variables

View Source
var (
	// OK indicates the operation was successful.
	OK = ErrCode{/* contains filtered or unexported fields */}

	// NoContent indicates the operation was successful with no content.
	NoContent = ErrCode{/* contains filtered or unexported fields */}

	// Canceled indicates the operation was canceled (typically by the caller).
	Canceled = ErrCode{/* contains filtered or unexported fields */}

	// Unknown error. An example of where this error may be returned is
	// if a Status value received from another address space belongs to
	// an error-space that is not known in this address space. Also
	// errors raised by APIs that do not return enough error information
	// may be converted to this error.
	Unknown = ErrCode{/* contains filtered or unexported fields */}

	// InvalidArgument indicates client specified an invalid argument.
	// Note that this differs from FailedPrecondition. It indicates arguments
	// that are problematic regardless of the state of the system
	// (e.g., a malformed file name).
	InvalidArgument = ErrCode{/* contains filtered or unexported fields */}

	// DeadlineExceeded means operation expired before completion.
	// For operations that change the state of the system, this error may be
	// returned even if the operation has completed successfully. For
	// example, a successful response from a server could have been delayed
	// long enough for the deadline to expire.
	DeadlineExceeded = ErrCode{/* contains filtered or unexported fields */}

	// NotFound means some requested entity (e.g., file or directory) was
	// not found.
	NotFound = ErrCode{/* contains filtered or unexported fields */}

	// AlreadyExists means an attempt to create an entity failed because one
	// already exists.
	AlreadyExists = ErrCode{/* contains filtered or unexported fields */}

	// PermissionDenied indicates the caller does not have permission to
	// execute the specified operation. It must not be used for rejections
	// caused by exhausting some resource (use ResourceExhausted
	// instead for those errors). It must not be
	// used if the caller cannot be identified (use Unauthenticated
	// instead for those errors).
	PermissionDenied = ErrCode{/* contains filtered or unexported fields */}

	// ResourceExhausted indicates some resource has been exhausted, perhaps
	// a per-user quota, or perhaps the entire file system is out of space.
	ResourceExhausted = ErrCode{/* contains filtered or unexported fields */}

	// FailedPrecondition indicates operation was rejected because the
	// system is not in a state required for the operation's execution.
	// For example, directory to be deleted may be non-empty, an rmdir
	// operation is applied to a non-directory, etc.
	FailedPrecondition = ErrCode{/* contains filtered or unexported fields */}

	// Aborted indicates the operation was aborted, typically due to a
	// concurrency issue like sequencer check failures, transaction aborts,
	// etc.
	Aborted = ErrCode{/* contains filtered or unexported fields */}

	// OutOfRange means operation was attempted past the valid range.
	// E.g., seeking or reading past end of file.
	//
	// Unlike InvalidArgument, this error indicates a problem that may
	// be fixed if the system state changes. For example, a 32-bit file
	// system will generate InvalidArgument if asked to read at an
	// offset that is not in the range [0,2^32-1], but it will generate
	// OutOfRange if asked to read from an offset past the current
	// file size.
	//
	// There is a fair bit of overlap between FailedPrecondition and
	// OutOfRange. We recommend using OutOfRange (the more specific
	// error) when it applies so that callers who are iterating through
	// a space can easily look for an OutOfRange error to detect when
	// they are done.
	OutOfRange = ErrCode{/* contains filtered or unexported fields */}

	// Unimplemented indicates operation is not implemented or not
	// supported/enabled in this service.
	Unimplemented = ErrCode{/* contains filtered or unexported fields */}

	// Internal errors. Means some invariants expected by underlying
	// system has been broken. If you see one of these errors,
	// something is very broken.
	Internal = ErrCode{/* contains filtered or unexported fields */}

	// Unavailable indicates the service is currently unavailable.
	// This is a most likely a transient condition and may be corrected
	// by retrying with a backoff. Note that it is not always safe to retry
	// non-idempotent operations.
	//
	// See litmus test above for deciding between FailedPrecondition,
	// Aborted, and Unavailable.
	Unavailable = ErrCode{/* contains filtered or unexported fields */}

	// DataLoss indicates unrecoverable data loss or corruption.
	DataLoss = ErrCode{/* contains filtered or unexported fields */}

	// Unauthenticated indicates the request does not have valid
	// authentication credentials for the operation.
	Unauthenticated = ErrCode{/* contains filtered or unexported fields */}

	// TooManyRequest indicates that the client has made too many requests and
	// exceeded their rate limit and/or quota and must wait before making
	// futhur requests.
	TooManyRequests = ErrCode{/* contains filtered or unexported fields */}

	// InternalOnlyLog errors. Means some invariants expected by underlying
	// system has been broken. If you see one of these errors,
	// something is very broken. The error message is not sent to the client.
	InternalOnlyLog = ErrCode{/* contains filtered or unexported fields */}
)

Functions

func Check

func Check(val any) error

Check validates the provided model against it's declared tags.

func IsFieldErrors

func IsFieldErrors(err error) bool

IsFieldErrors checks if an error of type FieldErrors exists.

Types

type ErrCode

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

ErrCode represents an error code in the system.

func (ErrCode) Equal

func (ec ErrCode) Equal(ec2 ErrCode) bool

Equal provides support for the go-cmp package and testing.

func (ErrCode) MarshalText

func (ec ErrCode) MarshalText() ([]byte, error)

MarshalText implement the marshal interface for JSON conversions.

func (ErrCode) String

func (ec ErrCode) String() string

String returns the string representation of the error code.

func (*ErrCode) UnmarshalText

func (ec *ErrCode) UnmarshalText(data []byte) error

UnmarshalText implement the unmarshal interface for JSON conversions.

func (ErrCode) Value

func (ec ErrCode) Value() int

Value returns the integer value of the error code.

type Error

type Error struct {
	Code     ErrCode `json:"code"`
	Message  string  `json:"message"`
	FuncName string  `json:"-"`
	FileName string  `json:"-"`
}

Error represents an error in the system.

func New

func New(code ErrCode, err error) *Error

New constructs an error based on an app error.

func NewError

func NewError(err error) *Error

NewError checks for an Error in the error interface value. If it doesn't exist, will create one from the error.

func Newf

func Newf(code ErrCode, format string, v ...any) *Error

Newf constructs an error based on a error message.

func (*Error) Encode

func (e *Error) Encode() ([]byte, string, error)

Encode implements the encoder interface.

func (*Error) Equal

func (e *Error) Equal(e2 *Error) bool

Equal provides support for the go-cmp package and testing.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) HTTPStatus

func (e *Error) HTTPStatus() int

HTTPStatus implements the web package httpStatus interface so the web framework can use the correct http status.

type FieldError

type FieldError struct {
	Field string `json:"field"`
	Err   string `json:"error"`
}

FieldError is used to indicate an error with a specific request field.

type FieldErrors

type FieldErrors []FieldError

FieldErrors represents a collection of field errors.

func GetFieldErrors

func GetFieldErrors(err error) FieldErrors

GetFieldErrors returns a copy of the FieldErrors pointer.

func NewFieldsError

func NewFieldsError(field string, err error) FieldErrors

NewFieldsError creates an fields error.

func (FieldErrors) Encode

func (fe FieldErrors) Encode() ([]byte, string, error)

Encode implements the encoder interface.

func (FieldErrors) Error

func (fe FieldErrors) Error() string

Error implements the error interface.

func (FieldErrors) Fields

func (fe FieldErrors) Fields() map[string]string

Fields returns the fields that failed validation

Jump to

Keyboard shortcuts

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