resp

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrSuccess - 200: OK.
	ErrSuccess int = iota + 100001

	// ErrUnknown - 500: Internal server error.
	ErrUnknown

	// ErrBind - 400: Error occurred while binding the request body to the struct.
	ErrBind

	// ErrValidation - 400: Validation failed.
	ErrValidation

	// ErrTokenInvalid - 401: Token invalid.
	ErrTokenInvalid

	// ErrPageNotFound - 404: Page not found.
	ErrPageNotFound
)

Common: basic errors. Code must start with 1xxxxx.

View Source
const (
	// ErrEncrypt - 401: Error occurred while encrypting the user password.
	ErrEncrypt int = iota + 100201

	// ErrSignatureInvalid - 401: Signature is invalid.
	ErrSignatureInvalid

	// ErrExpired - 401: Token expired.
	ErrExpired

	// ErrInvalidAuthHeader - 401: Invalid authorization header.
	ErrInvalidAuthHeader

	// ErrMissingHeader - 401: The `Authorization` header was empty.
	ErrMissingHeader

	// ErrPasswordIncorrect - 401: Password was incorrect.
	ErrPasswordIncorrect

	// ErrPermissionDenied - 403: Permission denied.
	ErrPermissionDenied
)

common: authorization and authentication errors.

View Source
const (
	// ErrEncodingFailed - 500: Encoding failed due to an error with the data.
	ErrEncodingFailed int = iota + 100301

	// ErrDecodingFailed - 500: Decoding failed due to an error with the data.
	ErrDecodingFailed

	// ErrInvalidJSON - 500: Data is not valid JSON.
	ErrInvalidJSON

	// ErrEncodingJSON - 500: JSON data could not be encoded.
	ErrEncodingJSON

	// ErrDecodingJSON - 500: JSON data could not be decoded.
	ErrDecodingJSON

	// ErrInvalidYaml - 500: Data is not valid Yaml.
	ErrInvalidYaml

	// ErrEncodingYaml - 500: Yaml data could not be encoded.
	ErrEncodingYaml

	// ErrDecodingYaml - 500: Yaml data could not be decoded.
	ErrDecodingYaml
)

common: encode/decode errors.

View Source
const (
	// ErrDatabase - 500: Database error.
	ErrDatabase int = iota + 100101
)

common: database errors.

Variables

This section is empty.

Functions

func DBErr

func DBErr(err error) error

func EchoErrorHandler

func EchoErrorHandler(log log.Logger, handlerFunc ...ErrorHandler) func(err error, c echo.Context)

func ListResponse

func ListResponse(arr interface{}, total int64, c echo.Context) error

func Msg

func Msg(m string) error

func ParamErr

func ParamErr(err error) error

func Register added in v0.0.4

func Register(code int, httpStatus int, message string, refs ...string)

func Response

func Response(data interface{}, c echo.Context) error

func SignatureInvalid added in v0.0.3

func SignatureInvalid(err error) error

func Success

func Success(c echo.Context) error

func Unauthorized

func Unauthorized(err error) error

func UnknownErr

func UnknownErr(err error) error

Types

type ErrCode added in v0.0.3

type ErrCode struct {
	// C refers to the code of the ErrCode.
	C int

	// HTTP status that should be used for the associated error code.
	HTTP int

	// External (user) facing error text.
	Ext string

	// Ref specify the reference document.
	Ref string
}

ErrCode implements `github.com/marmotedu/errors`.Coder interface.

func (ErrCode) Code added in v0.0.3

func (coder ErrCode) Code() int

Code returns the integer code of ErrCode.

func (ErrCode) Error added in v0.0.3

func (coder ErrCode) Error() string

func (ErrCode) HTTPStatus added in v0.0.3

func (coder ErrCode) HTTPStatus() int

HTTPStatus returns the associated HTTP status code, if any. Otherwise, returns 200.

func (ErrCode) Reference added in v0.0.3

func (coder ErrCode) Reference() string

Reference returns the reference document.

func (ErrCode) String added in v0.0.3

func (coder ErrCode) String() string

String implements stringer. String returns the external error message, if any.

type ErrorHandler

type ErrorHandler func(ctx echo.Context)

Jump to

Keyboard shortcuts

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