httperror

package module
v0.0.0-...-426a3fc Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: GPL-3.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EchoHttpErrorHandler

func EchoHttpErrorHandler(server *echo.Echo) echo.HTTPErrorHandler

EchoHttpErrorHandler echo httpErrorhandler 兼容 自定义 httperror

func HttpErrorHandleMiddleware

func HttpErrorHandleMiddleware() echo.MiddlewareFunc

HttpErrorHandleMiddleware 错误处理

func IsHTTPError

func IsHTTPError(e interface{}) bool

IsHTTPError 判断是否是 HTTPError 类型

func Middleware

func Middleware() gin.HandlerFunc

Middleware 处理 HTTPError 错误

Types

type HTTPError

type HTTPError struct {

	// Http 状态码
	StatusCode int `json:"http_code"`
	// 错误消息
	Message string `json:"msg"`
	// 业务错误码
	Code int64 `json:"code"`
	// IsHttpError 标记
	IsHTTPError bool `json:"-"`
	// contains filtered or unexported fields
}

HTTPError 自定义HTTP 错误

func BadRequest

func BadRequest(message string, code int64) *HTTPError

BadRequest 400 参数校验失败

func InternalError

func InternalError(message string, code int64) *HTTPError

InternalError 500 系统内部错误

func New

func New(statusCode int, message string, code int64) *HTTPError

New 生成 HTTPError

func Parse

func Parse(e error, code int64) *HTTPError

func RequestNotAccept

func RequestNotAccept(message string, code int64) *HTTPError

RequestNotAccept 406 请求不可接受

func TryConstructHttpError

func TryConstructHttpError(err interface{}) (*HTTPError, bool)

TryConstructHttpError 尝试使用字符串或者httperror.HttpError 构建httperror

func (*HTTPError) Error

func (that *HTTPError) Error() string

Jump to

Keyboard shortcuts

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