xerr

package module
v0.0.0-...-c285e0e Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 7 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ServerError = New(500, "ServerError",
	"There was a little problem on the server side, please report it to us or try again later.")

ServerError always the same

Functions

func ErrorHandler

func ErrorHandler(err error, c echo.Context)

ErrorHandler customize echo's HTTP error handler.

func Is

func Is(err error, key string) bool

Is err the instance of Error,and has <key>?

func IsCode

func IsCode(err error, code int) bool

IsCode check if the status code is <code>

Types

type Error

type Error struct {
	Key     string `json:"error"`
	Message string `json:"message"`
	// contains filtered or unexported fields
}

Error custom struct

func New

func New(code int, key string, msg string) *Error

New Error

func Newf

func Newf(code int, key string, format string, a ...interface{}) *Error

Newf create a Error use format

func ParseResp

func ParseResp(resp *http.Response) *Error

ParseResp can parse http response, if there is a error, it would read and close the body for error messages.

func (*Error) Error

func (e *Error) Error() string

Error makes it compatible with `error` interface.

func (*Error) StatusCode

func (e *Error) StatusCode() int

StatusCode is http status code

Jump to

Keyboard shortcuts

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