response

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderTotalCount    = "X-Total-Count"
	HeaderTotalVp       = "X-Total-Vp"
	HeaderCurrentOffset = "X-Offset"
	HeaderLimit         = "X-Limit"
)
View Source
const (
	GeneralErrorKey = "_"
)

Variables

This section is empty.

Functions

func AddPaginationHeaders

func AddPaginationHeaders(w http.ResponseWriter, offset, limit, totalCnt uint64)

func AddTotalVpHeader added in v0.1.3

func AddTotalVpHeader(w http.ResponseWriter, vp float32)

func HandleError

func HandleError(err Error, w http.ResponseWriter)

func IsInternalError

func IsInternalError(err error) bool

IsInternalError returns false when the error is caused by invalid request data or by other mismatches caused by an user. It can be used to determine whether the error should be logged. If the function returns false, the error shouldn't be logged.

func ParseError

func ParseError(err Error) map[string]interface{}

ParseError determines the error type and creates a map with the error description.

Types

type BaseError

type BaseError struct{}

func (*BaseError) GetHTTPStatus

func (e *BaseError) GetHTTPStatus() int

type Error

type Error interface {
	PublicMessage() string
	GetHTTPStatus() int
}

func ResolveError

func ResolveError(err error) Error

type ErrorMessage

type ErrorMessage struct {
	Code    errs.ErrCode `json:"code"`
	Message string       `json:"message"`
}

func MissedValueError

func MissedValueError(message string) ErrorMessage

func WrongFormatError

func WrongFormatError(message string) ErrorMessage

func WrongValueError

func WrongValueError(message string) ErrorMessage

func (ErrorMessage) Error

func (e ErrorMessage) Error() string

type InternalError

type InternalError struct {
	BaseError
}

func NewInternalError

func NewInternalError() *InternalError

func (*InternalError) GetHTTPStatus

func (e *InternalError) GetHTTPStatus() int

func (*InternalError) PublicMessage

func (e *InternalError) PublicMessage() string

type NotFoundError

type NotFoundError struct {
	BaseError
}

func NewNotFoundError

func NewNotFoundError() *NotFoundError

func (*NotFoundError) GetHTTPStatus

func (e *NotFoundError) GetHTTPStatus() int

func (*NotFoundError) PublicMessage

func (e *NotFoundError) PublicMessage() string

type PermissionDeniedError

type PermissionDeniedError struct {
	BaseError
}

func NewPermissionDeniedError

func NewPermissionDeniedError() *PermissionDeniedError

func (*PermissionDeniedError) GetHTTPStatus

func (e *PermissionDeniedError) GetHTTPStatus() int

func (*PermissionDeniedError) PublicMessage

func (e *PermissionDeniedError) PublicMessage() string

type RateLimitedError

type RateLimitedError struct {
	BaseError

	// time in seconds
	RetryAfter int
}

func NewRateLimitedError

func NewRateLimitedError(retryAfter int) *RateLimitedError

func (*RateLimitedError) GetHTTPStatus

func (e *RateLimitedError) GetHTTPStatus() int

func (*RateLimitedError) PublicMessage

func (e *RateLimitedError) PublicMessage() string

type UnprocessableEntityError

type UnprocessableEntityError struct {
	ValidationError
}

func NewNotAcceptableError

func NewNotAcceptableError(details ...map[string]ErrorMessage) *UnprocessableEntityError

func (*UnprocessableEntityError) GetHTTPStatus

func (e *UnprocessableEntityError) GetHTTPStatus() int

func (*UnprocessableEntityError) PublicMessage

func (e *UnprocessableEntityError) PublicMessage() string

type ValidationError

type ValidationError struct {
	BaseError
	// contains filtered or unexported fields
}

func NewValidationError

func NewValidationError(details ...map[string]ErrorMessage) *ValidationError

func (*ValidationError) Errors

func (e *ValidationError) Errors() map[string]ErrorMessage

func (*ValidationError) GetHTTPStatus

func (e *ValidationError) GetHTTPStatus() int

func (*ValidationError) PublicMessage

func (e *ValidationError) PublicMessage() string

func (*ValidationError) SetError

func (e *ValidationError) SetError(key string, code errs.ErrCode, message string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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