error_utils

package
v0.0.0-...-5750976 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//OK 正常
	OK = &Exception{
		StatusCode: http.StatusOK,
		Code:       "",
		Message:    ""}
	//InternalError 内部错误
	InternalError = &Exception{
		StatusCode: http.StatusInternalServerError,
		Code:       "InternalError",
		Message:    "Internal server error"}
	//BadRequest 错误请求
	BadRequest = &Exception{
		StatusCode: http.StatusBadRequest,
		Code:       "InvalidParameter",
		Message:    "Error occurred while binding the request body to the struct."}
	//InvalidHeader 无效的头参数
	InvalidHeader = &Exception{
		StatusCode: http.StatusBadRequest,
		Code:       "InvalidHeader",
		Message:    "some header meta does not exist."}
	//InvalidURL 无效请求
	InvalidURL = &Exception{
		StatusCode: http.StatusNotFound,
		Code:       "InvalidURL",
		Message:    "Invalid URL or action"}
	//MissingParameter 缺失参数
	MissingParameter = &Exception{
		StatusCode: http.StatusBadRequest,
		Code:       "MissingParameter",
		Message:    "The mandatory parameter '%s' is missing."}
	//InvalidParameter 无效的参数
	InvalidParameter = &Exception{
		StatusCode: http.StatusBadRequest,
		Code:       "InvalidParameter",
		Message:    "The parameter '%s'  was not correct, error info: %s."}
	//Json格式化数据异常
	JsonFormatError = &Exception{
		StatusCode: http.StatusBadRequest,
		Code:       "JsonFormatError",
		Message:    "Format json to model error."}
	//UnKnownError 未知错误,匹配不到错误码
	UnKnownError = &Exception{
		StatusCode: http.StatusBadRequest,
		Code:       "UnKnownError",
		Message:    "An unknown error."}
	//TimeoutError 调用第三方服务超时
	TimeoutError = &Exception{
		StatusCode: http.StatusServiceUnavailable,
		Code:       "TimeoutError",
		Message:    "The request timed out %s times(%s for retry)"}
	// 依赖第三方服务异常
	DependencyServiceError = &Exception{
		StatusCode: http.StatusServiceUnavailable,
		Code:       "DependencyServiceError",
		Message:    "Call dependency service %s error, error response: %s."}
)

Functions

func FormatError

func FormatError(err error, args ...interface{}) error

FormatError,错误信息格式化 参数:

err、args

返回:

error

Types

type Exception

type Exception struct {
	StatusCode int
	Code       string
	Message    string
}

func NormalizeError

func NormalizeError(err error) (exc *Exception)

NormalizeError,错误统一 参数:

error

返回:

*Exception

func (Exception) Error

func (err Exception) Error() string

Jump to

Keyboard shortcuts

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