utils

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNS                   = errorx.NewNamespace("error.api")
	ErrUnknown              = ErrNS.NewType("unknown")
	ErrInvalidRequest       = ErrNS.NewType("invalid_request")
	ErrInternalServer       = ErrNS.NewType("internal_server_error")
	ErrNotFound             = ErrNS.NewType("resource_not_found")
	ErrNoClusterPrivilege   = ErrNS.NewType("no_cluster_privilege")
	ErrNoNamespacePrivilege = ErrNS.NewType("no_namespace_privilege")
)

Functions

func AuthRequired added in v1.1.0

func AuthRequired(c *gin.Context)

func MWHandleErrors

func MWHandleErrors() gin.HandlerFunc

MWHandleErrors creates a middleware that turns (last) error in the context into an APIError json response. In handlers, `c.Error(err)` can be used to attach the error to the context. When error is attached in the context: - The handler can optionally assign the HTTP status code. - The handler must not self-generate a response body.

func SetErrorForGinCtx added in v1.1.0

func SetErrorForGinCtx(c *gin.Context, err error)

Types

type APIError

type APIError struct {
	Message  string `json:"message"`
	Code     string `json:"code"`
	FullText string `json:"full_text"`
	Status   string `json:"status"`
}

Jump to

Keyboard shortcuts

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