apierrors

package
v0.0.0-...-eca782c Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: Apache-2.0 Imports: 7 Imported by: 6

Documentation

Index

Constants

View Source
const (
	APIErrorDetail errorutil.DetailTag = "api"
	TenantDetail   errorutil.DetailTag = "tenant"
)

Variables

View Source
var ValidationFailed = Invalid.WithReason("ValidationFailed")

Functions

func IsAPIError

func IsAPIError(err error) bool

func IsKind

func IsKind(err error, kind Kind) bool

func NewBadRequest

func NewBadRequest(msg string) error

func NewDataRace

func NewDataRace(msg string) error

func NewForbidden

func NewForbidden(msg string) error

func NewInternalError

func NewInternalError(msg string) error

func NewInvalid

func NewInvalid(msg string) error

func NewNotFound

func NewNotFound(msg string) error

func NewTooManyRequest

func NewTooManyRequest(msg string) error

func NewUnauthorized

func NewUnauthorized(msg string) error

Types

type APIError

type APIError struct {
	Kind
	Message string  `json:"message"`
	Code    int     `json:"code"`
	Info    Details `json:"info,omitempty"`
}

func AsAPIError

func AsAPIError(err error) *APIError

func (*APIError) Clone

func (e *APIError) Clone() *APIError

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) FillDetails

func (e *APIError) FillDetails(details Details)

func (*APIError) HasCause

func (e *APIError) HasCause(kind string) bool

func (*APIError) SkipLogging

func (e *APIError) SkipLogging() bool

type Cause

type Cause interface{ Kind() string }

type Details

type Details = errorutil.Details

type Kind

type Kind struct {
	Name   Name   `json:"name"`
	Reason string `json:"reason"`

	IsSkipLoggingToExternalService bool `json:"-"`
}

func (Kind) New

func (k Kind) New(msg string) error

New is a shorthand of NewWithInfo with an empty Details.

func (Kind) NewWithCause

func (k Kind) NewWithCause(msg string, c Cause) error

func (Kind) NewWithCauses

func (k Kind) NewWithCauses(msg string, cs []Cause) error

func (Kind) NewWithInfo

func (k Kind) NewWithInfo(msg string, info Details) error

NewWithInfo wraps all value in info with APIErrorDetail, making them appear in the response.

func (Kind) SkipLoggingToExternalService

func (k Kind) SkipLoggingToExternalService() Kind

type MapCause

type MapCause struct {
	CauseKind string
	Data      map[string]interface{}
}

func (MapCause) Kind

func (c MapCause) Kind() string

func (MapCause) MarshalJSON

func (c MapCause) MarshalJSON() ([]byte, error)

type Name

type Name string
const (
	BadRequest            Name = "BadRequest"
	Invalid               Name = "Invalid"
	Unauthorized          Name = "Unauthorized"
	Forbidden             Name = "Forbidden"
	NotFound              Name = "NotFound"
	AlreadyExists         Name = "AlreadyExists"
	DataRace              Name = "DataRace"
	TooManyRequest        Name = "TooManyRequest"
	InternalError         Name = "InternalError"
	ServiceUnavailable    Name = "ServiceUnavailable"
	RequestEntityTooLarge Name = "RequestEntityTooLarge"
)

func (Name) HTTPStatus

func (n Name) HTTPStatus() int

func (Name) WithReason

func (n Name) WithReason(reason string) Kind

type StringCause

type StringCause string

func (StringCause) Kind

func (c StringCause) Kind() string

func (StringCause) MarshalJSON

func (c StringCause) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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