errorresp

package
v1.0.0-rc Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package errorresp 封装了错误定义

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrResp

func ErrResp(e error) (httpserver.Responser, error)

ErrResp 根据 error 转为一个 http error response.

func ErrWrite

func ErrWrite(e error, w http.ResponseWriter) error

ErrWrite 根据 error 写入标准错误格式

func IsNotFound

func IsNotFound(e error) bool

Types

type APIError

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

APIError 接口错误

func New

func New(options ...Option) *APIError

New 新建接口错误

func (*APIError) AccessDenied

func (e *APIError) AccessDenied() *APIError

AccessDenied 无权限

func (*APIError) AlreadyExists

func (e *APIError) AlreadyExists() *APIError

AlreadyExists 资源已存在

func (*APIError) Code

func (e *APIError) Code() string

Code 错误码

func (*APIError) Error

func (e *APIError) Error() string

Error 错误信息

func (*APIError) ErrorVerificationCode

func (e *APIError) ErrorVerificationCode(err error) *APIError

ErrorVerificationCode 验证码错误

func (*APIError) HttpCode

func (e *APIError) HttpCode() int

HttpCode HTTP错误码

func (*APIError) InternalError

func (e *APIError) InternalError(err error) *APIError

InternalError 异常

func (*APIError) InvalidParameter

func (e *APIError) InvalidParameter(err interface{}) *APIError

InvalidParameter 参数错误

func (*APIError) InvalidState

func (e *APIError) InvalidState(err string) *APIError

InvalidState 状态异常

func (*APIError) MissingParameter

func (e *APIError) MissingParameter(err string) *APIError

MissingParameter 缺少参数

func (*APIError) NotFound

func (e *APIError) NotFound() *APIError

NotFound 资源不存在

func (*APIError) NotLogin

func (e *APIError) NotLogin() *APIError

NotLogin 未登录

func (*APIError) Render

func (e *APIError) Render(localeResource *i18n.LocaleResource) string

func (*APIError) ToResp

func (e *APIError) ToResp() httpserver.Responser

ToResp 根据 APIError 转为一个 http error response.

func (*APIError) Write

func (e *APIError) Write(w http.ResponseWriter) error

Write 将错误写入 http.ResponseWriter

type MetaMessage

type MetaMessage struct {
	Key     string
	Args    []interface{}
	Default string
}

type Option

type Option func(*APIError)

Option 可选参数

func WithCode

func WithCode(httpCode int, code string) Option

func WithMessage

func WithMessage(msg string) Option

WithMessage 初始化 msg

func WithTemplateMessage

func WithTemplateMessage(template, defaultValue string, args ...interface{}) Option

WithTemplateMessage 初始化 msg

Jump to

Keyboard shortcuts

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